自定义窗口的玻璃效果(边框,标题栏...) 限制
在WPF里边如果WM_NCCALCSIZE占满整个窗口,来扩展整个窗口为Client,去自定义标题栏,会有两个问题。
1:Window下边的Root的容器(Panel,Grid)会依然使用原有Client的大小,(vcommon注:resize之后依然在现在Window大小里减去原有Frame的宽度),导致下边和右边无法绘制。
2:DwmDefWindowProc在HwndSource.FromHwnd(hwnd).AddHook的Hook函数中完全无效。
解决方法很讨厌:Workaround
1:根据微软的文档: http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx
<Window.Template>
<ControlTemplate>
<Canvas x:Name="CanvasAll" Width="{TemplateBinding Window.ActualWidth}" Height="{TemplateBinding Window.ActualHeight}">
</Canvas>
</ControlTemplate>
</Window.Template>
2: 不使用Hook,用C++ Dll的SetWindowLong中的WndProc里调用 DwmDefWindowProc
另:
这个是最大化的时候一个问题(不确定):
// Tricky bit. Due to a bug in DwmDefWindowProc()'s handling of
// WM_NCHITTEST, having any nonclient area atop the window causes the
// caption buttons to draw onscreen but not respond to mouse hover/clicks.
// So for a taskbar at the screen top, we can't push the client_rect->top
// down; instead, we move the bottom up by one pixel, which is the
// smallest change we can make and still get a client area less than the
// screen size. This is visibly ugly, but there seems to be no better
// solution.
最大化后右上角的标题按钮Close Min Max都无法相应鼠标移动消息,DwmDefWindowProc响应有问题,
所以解决办法就是客户区域不填满整个窗口.把最下方上移动一个像素.