网站大量收购独家精品文档,联系QQ:2885784924

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

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

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
[计算机]将玻璃框扩展到 WPF 应用程序

本主题演示如何将 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

文档评论(0)

ipbohn97 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档