在WPF中使用Areo玻璃效果:
首先定义结构体Margins
public struct Margins
{
public int left;
public int right;
public int top;
public int bottom;
public Margins(thickness t)
{
left=(int)t.Left;
right=(int)t.Right;
top=(int)t.Top;
bottom=(int )t.Bottom;
}
}
public class GlassHelper
{
[Dllimport("dwmapi.dll",preserveSig=false)]
public static extern bool DwmIsCompositionEnabled();
[Dllimport("dwmapi.dll",preserveSig=false)]
DwmExtendFrameIntoClientArea(IntPtr hwnd,ref Margins margins);
public bool AreoWindow(window win,thickness t)
{
if (!DwmIsCompositionEnabled()) return false;
IntPtr hwnd=new WindowInteropHelper(win).Handle;
if (hwnd=hwnd.Zero) throw new InvalidOperationException(no window is available);
win.Background=Brushes.Transparent;
hwndSource.FromHwnd(hwnd).CompositionTarget.BackColor=Colors.Transparent;
Margins m=new Margins(t);
DwmExtendFrameIntoClientArea(IntPtr hwnd,ref m);
}
}
具体的可参考http://msdn.microsoft.com/zh-cn/library/ms748975.aspx#Y404