![[計算機(jī)]將玻璃框擴(kuò)展到WPF應(yīng)用程序_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678531.gif)
![[計算機(jī)]將玻璃框擴(kuò)展到WPF應(yīng)用程序_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678532.gif)
![[計算機(jī)]將玻璃框擴(kuò)展到WPF應(yīng)用程序_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678533.gif)
![[計算機(jī)]將玻璃框擴(kuò)展到WPF應(yīng)用程序_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678534.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、.本主題演示如何將 Windows Vista 玻璃框擴(kuò)展至 Windows Presentation Foundation (WPF) 應(yīng)用程序的工作區(qū)。說明:此示例僅在運行已啟用玻璃效果的桌面窗口管理器 (DWM) 的 Windows Vista 計算機(jī)上才會起作用。Windows Vista Home Basic 版本不支持透明玻璃效果。通常利用透明玻璃效果呈現(xiàn)的區(qū)域在其他版本的 Windows Vista 上呈現(xiàn)為不透明。 示例 下面的示例演示一個已擴(kuò)展到 Internet Explorer 7 地址欄的玻璃框。Internet Explorer,擴(kuò)展的玻璃框位于地址欄后。若
2、要在 WPF 應(yīng)用程序上擴(kuò)展玻璃框,需要訪問非托管的 API。下面的代碼示例為擴(kuò)展玻璃框工作區(qū)所需的兩個 API 執(zhí)行平臺調(diào)用 (pinvoke)。每個 API 都是在名為 NonClientRegionAPI 的類中聲明的。C# 復(fù)制代碼 StructLayout(LayoutKind.Sequential)public struct MARGINS public int cxLeftWidth; / width of left border that retains its size public int cxRightWidth; / width of right border that
3、 retains its size public int cyTopHeight; / height of top border that retains its size public int cyBottomHeight; / height of bottom border that retains its size;DllImport("DwmApi.dll")public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset);DwmExtendFrame
4、IntoClientArea 是用于將框擴(kuò)展到工作區(qū)中的 DWM 函數(shù)。它有兩個參數(shù),一個窗口句柄,一個 MARGINS 結(jié)構(gòu)。MARGINS 用于告知 DWM 框擴(kuò)展到工作區(qū)中時延伸的程度。若要使用 DwmExtendFrameIntoClientArea 函數(shù),必須獲取一個窗口句柄。在 WPF 中,可以通過 HwndSource 的 Handle 屬性獲取窗口句柄。在下面的示例中,框擴(kuò)展至窗口的 Loaded 事件的工作區(qū)。C# 復(fù)制代碼 void OnLoaded(object sender, RoutedEventArgs e) try / Obtain the window hand
5、le for WPF application IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0); / Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.
6、FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; / Set Margins NonClientRegionAPI.MARGINS margins = new NonClientRegionAPI.MARGINS(); / Extend glass frame into client area / Note that the default desktop Dpi is 96dpi. The margins are / adjusted for the sys
7、tem Dpi. margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96); margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96); margins.cyTopHeight = Convert.ToInt32(int)topBar.ActualHeight + 5) * (DesktopDpiX / 96); margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96); int hr = Non
8、ClientRegionAPI.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); / if (hr < 0) /DwmExtendFrameIntoClientArea Failed / If not Vista, paint background white. catch (DllNotFoundException) Application.Current.MainWindow.Background = Brushes.White; 下面的示例演示一個簡單的窗口,在此窗口中框擴(kuò)展至工作區(qū)。此框擴(kuò)展到上邊框的
9、后面,上邊框包含兩個 TextBox 對象。C# 復(fù)制代碼 <Window x:Class="SDKSample.Window1" xmlns=" xmlns:x=" Title="Extended Glass in WPF" Height="300" Width="400" Loaded="OnLoaded" Background="Transparent" > <Grid ShowGridLines="True"&
10、gt; <DockPanel Name="mainDock"> <!- The border is used to compute the rendered height with margins. topBar contents will be displayed on the extended glass frame.-> <Border Name="topBar" DockPanel.Dock="Top" > <Grid Name="grid"> <Gri
11、d.ColumnDefinitions> <ColumnDefinition MinWidth="100" Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" MinWidth="100" Margin="0,0,10,5">Path</TextBox> <TextBox Grid.Column="1" MinWidth="75" Margin="0,0,0,5">Search</TextBox> </Grid> </Border> <Grid DockPanel.Dock="Top" > <Grid.ColumnDefinitions> <ColumnDefinition/> </Grid.ColumnDefi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個人金銀首飾抵押借款合同樣本
- 不動產(chǎn)權(quán)益轉(zhuǎn)讓合同-土地與廠房
- 個人合伙買賣合同樣本
- 上海市重大裝備進(jìn)口合同
- 個人與個人借款合同標(biāo)準(zhǔn)版范文
- 2025年多邊培訓(xùn)合作組織協(xié)議文本
- 2025年充電樁運營管理合作協(xié)議模板
- 個人房屋抵押債權(quán)合同樣本
- 五金用品合同范本:詳細(xì)條款解析
- 買賣合同樣本原件
- 【可行性報告】2024年數(shù)據(jù)標(biāo)注與審核項目可行性研究分析報告
- 2024-2025學(xué)年滬科版數(shù)學(xué)七年級上冊期末綜合測試卷(一)(含答案)
- 2025門診護(hù)理工作計劃
- 《針法灸法》課件-溫灸器灸
- 電氣領(lǐng)域知識培訓(xùn)課件
- 針對老年人的交通安全宣傳
- 陜西省咸陽市2023-2024學(xué)年高一上學(xué)期期末考試 數(shù)學(xué) 含答案
- 新員工入職登記表模板表格(標(biāo)準(zhǔn)版)
- 天津市河北區(qū)2024-2025學(xué)年八年級上學(xué)期11月期中歷史試題(含答案)
- 初中數(shù)學(xué)幾何《將軍飲馬》模型題匯編含答案解析
- 小兒高熱驚厥課件
評論
0/150
提交評論