![[計算機]將玻璃框擴展到WPF應(yīng)用程序_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678531.gif)
![[計算機]將玻璃框擴展到WPF應(yīng)用程序_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678532.gif)
![[計算機]將玻璃框擴展到WPF應(yīng)用程序_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/16/18541bdf-033f-4eab-8506-954290367853/18541bdf-033f-4eab-8506-9542903678533.gif)
![[計算機]將玻璃框擴展到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),請進行舉報或認領(lǐng)
文檔簡介
1、.本主題演示如何將 Windows Vista 玻璃框擴展至 Windows Presentation Foundation (WPF) 應(yīng)用程序的工作區(qū)。說明:此示例僅在運行已啟用玻璃效果的桌面窗口管理器 (DWM) 的 Windows Vista 計算機上才會起作用。Windows Vista Home Basic 版本不支持透明玻璃效果。通常利用透明玻璃效果呈現(xiàn)的區(qū)域在其他版本的 Windows Vista 上呈現(xiàn)為不透明。 示例 下面的示例演示一個已擴展到 Internet Explorer 7 地址欄的玻璃框。Internet Explorer,擴展的玻璃框位于地址欄后。若
2、要在 WPF 應(yīng)用程序上擴展玻璃框,需要訪問非托管的 API。下面的代碼示例為擴展玻璃框工作區(qū)所需的兩個 API 執(zhí)行平臺調(diào)用 (pinvoke)。每個 API 都是在名為 NonClientRegionAPI 的類中聲明的。C# 復制代碼 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 是用于將框擴展到工作區(qū)中的 DWM 函數(shù)。它有兩個參數(shù),一個窗口句柄,一個 MARGINS 結(jié)構(gòu)。MARGINS 用于告知 DWM 框擴展到工作區(qū)中時延伸的程度。若要使用 DwmExtendFrameIntoClientArea 函數(shù),必須獲取一個窗口句柄。在 WPF 中,可以通過 HwndSource 的 Handle 屬性獲取窗口句柄。在下面的示例中,框擴展至窗口的 Loaded 事件的工作區(qū)。C# 復制代碼 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; 下面的示例演示一個簡單的窗口,在此窗口中框擴展至工作區(qū)。此框擴展到上邊框的
9、后面,上邊框包含兩個 TextBox 對象。C# 復制代碼 <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)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學年新教材高中生物 第二章 基因和染色體的關(guān)系 微專題四 伴性遺傳的解題方法說課稿 新人教版必修第二冊
- 別墅電梯出售合同范例
- 2023九年級數(shù)學下冊 第二十九章 投影與視圖29.1 投影第2課時 正投影說課稿 (新版)新人教版001
- 2024年四年級英語上冊 Unit 3 Let's Go Lesson 15 In the City說課稿 冀教版(三起)
- 2024年四年級英語上冊 Unit 1 My classroom The fifth period(第五課時)說課稿 人教PEP
- 6 我們神圣的國土 說課稿-2023-2024學年道德與法治五年級上冊統(tǒng)編版
- 個人發(fā)包合同范本
- 化妝品融資合同范例
- 供電部門保潔合同范例
- Unit1《Greetings》(說課稿)-2024-2025學年滬教版(五四制)(2024)英語一年級上冊
- 2023年廣東省公務(wù)員錄用考試《行測》真題及答案解析
- 陜西省咸陽市2023-2024學年高一上學期期末考試 數(shù)學 含答案
- 新員工入職登記表模板表格(標準版)
- 天津市河北區(qū)2024-2025學年八年級上學期11月期中歷史試題(含答案)
- 初中數(shù)學幾何《將軍飲馬》模型題匯編含答案解析
- 小兒高熱驚厥課件
- 劉潤年度演講2024
- 學校突發(fā)事件應(yīng)急流程
- 陜西省2024年中考語文真題試卷【附答案】
- 河南省鄭州市二七區(qū)2023-2024學年七年級下學期期末考試語文試題
- 燃氣經(jīng)營安全重大隱患判定標準課件
評論
0/150
提交評論