wpf 透明效果 需要DwmApi.dll文件,然后定义一个函数去画Aero区域,从而实现整个窗口的Aero化。
2016-08-30 14:51
706 查看
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;
}
}
[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);
{
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;
}
}
[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);
相关文章推荐
- .定义两个数组,首先把两个数组合并成一个新数组,然后把新数组中的所有元素逆序排列,需要实现的效果如图-2所示。
- 面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了;面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为(转)
- .定义两个数组,首先把两个数组合并成一个新数组,然后把新数组中的所有元素逆序排列,需要实现的效果如图-2所示。
- C/C++语言之通过定义指针函数方式来实现在一个cpp文件里面获取另外一个cpp文件函数的返回值
- 函数声明放在头文件中,函数的定义放在实现文件中,然后在主函数中调用
- c++ 模版函数的定义和实现放在一个文件中
- c++ 模版函数的定义和实现必须放在一个文件中
- 实现c++,java,lua 在c++编写后需要在 pkg 文件中添加新的函数 然后批处理下生成GamePlatformToLua
- WPF中,如何将Vista Aero效果扩展到整个窗口
- WPF中,如何将Vista Aero效果扩展到整个窗口
- [Win32 & GDI+Flat] 用分层窗口实现简单仿Aero透明效果
- c++ 模版函数的定义和实现放在一个文件中 .
- 头文件里面实现一个函数,在两个cpp中包含,则重复定义,如果加上inline则不会报错
- c++ 模版函数的定义和实现放在一个文件中
- 用 AnimateWindow 函数实现窗口动画效果
- 不错的用resizeTo和moveTo两个函数实现窗口的“打乒乓球”效果
- 不错的用resizeTo和moveTo两个函数实现窗口的“打乒乓球”效果
- 求高手指教,我有一个会员登陆文件页面,我想在会员点登陆弹出新窗口,然后自动关闭登陆窗口
- 实现一个函数,对一个正整数n,算得到1需要的最少操作次数?
- 将DLL中的导出函数表导出到一定义(.DEF)文件