在重绘标题栏时,一般只要重载WN_NCPAINT消息即可,但是这并不完美,因为在程序第一次启动时微软的系统按钮还是会闪一下,基本是重绘标题栏的软肋,通过spyXX查看发现有这么一个消息:
<00026> 0004097E S message:
0x00AE [未知] wParam:00001001 lParam:00000000
<00027> 0004097E R message:
0x00AE [未知] lResult:00000000
该消息没有在winuser.h中定义,ps:这就是微软的技术壁垒~~~
查看了一下chrome的源码,确实是这个消息在作怪。下面是chrome代码里的说明:
// These two messages aren't defined in winuser.h, but they are sent to windows
// with captions.
They appear to paint the window caption and frame.
// Unfortunately if you override the standard non-client rendering as we do
// with CustomFrameWindow, sometimes Windows (not deterministically
// reproducibly but definitely frequently) will send these messages to the
// window and paint the standard caption/title over the top of the custom one.
// So we need to handle these messages in CustomFrameWindow to prevent this
// from happening.
const int WM_NCUAHDRAWCAPTION = 0xAE;
const int WM_NCUAHDRAWFRAME = 0xAF;
我英文不是很好,大致的意思就是要重绘标题栏要对这两个消息响应。在看看chrome里是怎么响应的:
LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param,
LPARAM l_param)
{
// See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for
// an explanation about why we need to handle this message.
SetMsgHandled(!non_client_view_->UseNativeFrame());
return 0;
}
有效语句就一句, SetMsgHandled(!non_client_view_->UseNativeFrame());意思是就是不用原生标题栏时,设置该消息已响应,不再继续传给默认消息处理函数。
无图无真相:
不响应2个消息的效果:
响应2个消息的效果:
效果不错。 接下来就是画图的问题了,开始大航海吧~~
呵呵,鄙人表达能力欠缺,要是没看懂就Q我,450885099