[計算機]將玻璃框擴展到WPF應用程序_第1頁
[計算機]將玻璃框擴展到WPF應用程序_第2頁
[計算機]將玻璃框擴展到WPF應用程序_第3頁
[計算機]將玻璃框擴展到WPF應用程序_第4頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論