简体   繁体   English

使非客户区域无效

[英]Invalidating non-client areas

I've a window which has custom border/caption, in order to do that I handle WM_NCPAINT message. 我有一个具有自定义边框/标题的窗口,为此我处理WM_NCPAINT消息。 My caption has two backgrounds a brighter one for the active window, and a darker one for the background window. 我的标题有两个背景,一个用于活动窗口,另一个用于背景窗口。

But under some circumstances, for example when the window loses/gain focus, my caption is not updated so I end with the wrong background. 但在某些情况下,例如当窗口失去/获得焦点时,我的标题不会更新,所以我以错误的背景结束。

Until now I've handled WM_NCACTIVATE, and send a RedrawWindow(hwnd, NULL, NULL, RDW_FRAME|RDW_INVALIDATE), but this causes the whole window to repaint. 到目前为止,我已经处理了WM_NCACTIVATE,并发送了RedrawWindow(hwnd,NULL,NULL,RDW_FRAME | RDW_INVALIDATE),但这会导致整个窗口重新绘制。 Do you have any advice about this? 你有什么建议吗?

Actually, this does the trick: 实际上,这就是诀窍:

SetWindowPos(hwnd, 0, 0, 0, 0, 0,
    SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER);

Overriding non-client area is always fraught with peril. 压倒一切的非客户区总是充满了危险。 It seems the Window manager makes a lot of assumptions for optimization. 似乎Window管理器对优化做了很多假设。 Clearly it can be done, see Office, but it might take a lot of experimentation. 显然可以做到,请参阅Office,但可能需要进行大量实验。

Just an idea. 只是一个想法。 Call RedrawWindow twice, once to invalidate the non-client area then again to validate the client area. 调用RedrawWindow两次,一次使非客户区无效,然后再次验证客户区。

RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
RedrawWidnow(hwnd, NULL, NULL, RDW_NOFRAME | RDW_VALIDATE);

Another idea is to try to paint just the frame immediately, without invalidating anything: 另一个想法是尝试立即绘制框架,而不会使任何内容失效:

RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_UPDATENOW | RDW_NOCHILDREN);

Yet another idea is to specify an empty RECT or HREGION in the 2nd or 3rd parameters. 另一个想法是在第二或第三参数中指定空的RECT或HREGION。 It might not invalidate the client area that way. 它可能不会使客户区无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM