下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、.本主題演示如何將 Windows Vista 玻璃框擴展至 Windows Presentation Foundation (WPF) 應用程序的工作區(qū)。說明:此示例僅在運行已啟用玻璃效果的桌面窗口管理器 (DWM) 的 Windows Vista 計算機上才會起作用。Windows Vista Home Basic 版本不支持透明玻璃效果。通常利用透明玻璃效果呈現(xiàn)的區(qū)域在其他版本的 Windows Vista 上呈現(xiàn)為不透明。 示例 下面的示例演示一個已擴展到 Internet Explorer 7 地址欄的玻璃框。Internet Explorer,擴展的玻璃框位于地址欄后。若
2、要在 WPF 應用程序上擴展玻璃框,需要訪問非托管的 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 結構。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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電子商務平臺SEO優(yōu)化服務合同
- 2025版五金電料環(huán)保認證及銷售推廣合同范本3篇
- 2025年度股權轉(zhuǎn)讓合同終止后反悔及后續(xù)權益保障協(xié)議
- 2025年度船舶貨物運輸與港口操作服務合同
- 二零二五年度冷鏈物流冷鏈運輸冷鏈倉儲環(huán)境監(jiān)測合同簡易版
- 2025年度租賃挖機租賃合同不可抗力條款
- 二零二五年度商業(yè)地產(chǎn)貸款房屋買賣合同電子版
- 二零二五年度電子產(chǎn)品維修與銷售一體化合同
- 2025年度特色小吃炊事員品牌推廣聘用合同
- 二零二五年度貨運代理服務合同(含貨物檢驗)
- JB-T 8532-2023 脈沖噴吹類袋式除塵器
- 深圳小學英語單詞表(中英文)
- 護理質(zhì)量反饋內(nèi)容
- 山東省濟寧市2023年中考數(shù)學試題(附真題答案)
- 抖音搜索用戶分析報告
- 板帶生產(chǎn)工藝熱連軋帶鋼生產(chǎn)
- 鉆孔灌注樁技術規(guī)范
- 2023-2024學年北師大版必修二unit 5 humans and nature lesson 3 Race to the pole 教學設計
- 供貨進度計劃
- 國際尿失禁咨詢委員會尿失禁問卷表
- 彌漫大B細胞淋巴瘤護理查房
評論
0/150
提交評論