日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Windows 7 扩展玻璃效果(Aero Glass)

發布時間:2025/3/20 windows 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows 7 扩展玻璃效果(Aero Glass) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

???? Windows 7 操作系統默認具有一款玻璃效果主題(Aero Glass)。如果選擇了該款主題,所有的應用程序標題欄都會處于玻璃透明效果(如下圖)。這個功能是由Desktop Window Manager(DWM)服務支持的。

???? 默認情況下,我們編寫的應用程序在Windows 7 中也只有標題欄和窗口框架會具備玻璃效果,其他區域仍是不透明狀態(如下圖)。如果想將程序整體都改為上圖IE 窗口的效果,可以使用DWM API 將玻璃區域進行擴展。

首先,從dwmapi.dll 中調取DwmExtendFrameIntoClientArea 方法。

[StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; }; [DllImport("DwmApi.dll")] public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset);

創建方法ExtendAeroGlass 方法,可將WPF Window窗口的Aero Glass 區域擴展。

private void ExtendAeroGlass(Window window) { try { // 為WPF程序獲取窗口句柄 IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; // 設置Margins MARGINS margins = new MARGINS(); // 擴展Aero Glass margins.cxLeftWidth = -1; margins.cxRightWidth = -1; margins.cyTopHeight = -1; margins.cyBottomHeight = -1; int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); if (hr < 0) { MessageBox.Show("DwmExtendFrameIntoClientArea Failed"); } } catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; } }

簡單制作一個WPF 界面。

<Window x:Class="WpfAeroGlass.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="layout"> <Button x:Name="btn" Content="Button" Margin="191,66,202,211" /> <CheckBox x:Name="checkBox" Content="Extend AeroGlass" Click="CheckBox_Checked" Height="24" Width="121" /> </Grid> </Window>

補充CheckBox 點擊事件,在其中啟用ExtendAeroGlass 方法。

private void CheckBox_Checked(object sender, RoutedEventArgs e) { if checkBox.IsChecked.Value) { this.Background = Brushes.Transparent; ExtendAeroGlass(this); } else { this.Background = Brushes.White; } }

演示效果

運行程序后,默認界面狀態。

點擊"Extend AeroGlass" 選框,界面中<Grid> 也將呈現玻璃效果。

Windows API

???? 通過Windows API Code Pack 可以對Aero Glass 效果進行開啟或關閉。在程序中加入Microsoft.WindowsAPICodePack.Shell 命名空間,調整AeroGlassCompositioinEnabled 完成開/關Aero Glass的效果。

GlassWindow.AeroGlassCompositionEnabled = checkBox.IsChecked.Value;

源代碼

WpfAeroGlass.zip

轉載于:https://blog.51cto.com/186067/1280594

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Windows 7 扩展玻璃效果(Aero Glass)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。