C# WinForm完成Win7 Aero通明後果代碼。本站提示廣大學習愛好者:(C# WinForm完成Win7 Aero通明後果代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是C# WinForm完成Win7 Aero通明後果代碼正文
在Vista體系以後,微軟為窗體法式供給了Aero磨砂的後果,以下圖。那末用C#若何來完成這類磨砂後果呢?

配景為我的桌面
那先上代碼吧:
[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int Left;
public int Right;
public int Top;
public int Bottom;
}
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern bool DwmIsCompositionEnabled();
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
if (DwmIsCompositionEnabled())
{
MARGINS margins = new MARGINS();
margins.Right = margins.Left = margins.Top = margins.Bottom = this.Width + this.Height;
DwmExtendFrameIntoClientArea(this.Handle, ref margins);
}
base.OnLoad(e);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if (DwmIsCompositionEnabled())
{
e.Graphics.Clear(Color.Black);
}
}
這中後果的完成重要是挪用了體系的dwmapi.dll。
dwmapi.dll是Microsoft Desktop Window Manager API(桌面窗口治理器DWM 的公用界面)的靜態鏈接庫,正常文件,重要用作桌面後果的api。DWM 是一種新界面,在除 Windows Vista Home Basic 以外的一切 Windows Vista 版本中均供給 DWM 界面。
所以這類後果只能在Vista以後的體系中應用。