好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

[计算机]将玻璃框扩展到wpf应用程序.doc

4页
  • 卖家[上传人]:tian****1990
  • 文档编号:71743810
  • 上传时间:2019-01-21
  • 文档格式:DOC
  • 文档大小:263.68KB
  • / 4 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 本主题演示如何将 Windows Vista 玻璃框扩展至 Windows Presentation Foundation (WPF) 应用程序的工作区说明:此示例仅在运行已启用玻璃效果的桌面窗口管理器 (DWM) 的 Windows Vista 计算机上才会起作用Windows Vista Home Basic 版本不支持透明玻璃效果通常利用透明玻璃效果呈现的区域在其他版本的 Windows Vista 上呈现为不透明 示例 下面的示例演示一个已扩展到 Internet Explorer 7 地址栏的玻璃框Internet Explorer,扩展的玻璃框位于地址栏后若要在 WPF 应用程序上扩展玻璃框,需要访问非托管的 API下面的代码示例为扩展玻璃框工作区所需的两个 API 执行平台调用 (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 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);DwmExtendFrameIntoClientArea 是用于将框扩展到工作区中的 DWM 函数。

      它有两个参数,一个窗口句柄,一个 MARGINS 结构MARGINS 用于告知 DWM 框扩展到工作区中时延伸的程度若要使用 DwmExtendFrameIntoClientArea 函数,必须获取一个窗口句柄在 WPF 中,可以通过 HwndSource 的 Handle 属性获取窗口句柄在下面的示例中,框扩展至窗口的 Loaded 事件的工作区C# 复制代码 void OnLoaded(object sender, RoutedEventArgs e){ try { // Obtain the window handle 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.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 system 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 = NonClientRegionAPI.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); // if (hr < 0) { //DwmExtendFrameIntoClientArea Failed } } // If not Vista, paint background white. catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; }}下面的示例演示一个简单的窗口,在此窗口中框扩展至工作区。

      此框扩展到上边框的后面,上边框包含两个 TextBox 对象C# 复制代码 Path Search 下图说明扩展至 WPF 应用程序的玻璃框。

      玻璃框扩展至一个WPF 应用程序。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.