Violation of non-client areas

I have a window with a custom border / label to do this, I am processing the WM_NCPAINT message. My title has two backgrounds brighter than one for the active window and darker for the background window.

But in some circumstances, for example, when a window loses / increases focus, my title does not update, therefore it ends up with an incorrect background.

So far I have been handling WM_NCACTIVATE and sending RedrawWindow (hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE), but this causes the whole window to be redrawn. Do you have any tips on this?

+4
source share
2 answers

Redefining a non-client area is always fraught with danger. Window manager seems to make a lot of assumptions for optimization. Clearly this can be done, see Office, but it can take a lot of experimentation.

Just an idea. Call RedrawWindow twice, once, to invalidate the non-client area, and then check the client area again.

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

Another idea is to try to draw a frame right away without making anything invalid:

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

Another idea is to specify an empty RECT or HREGION in the 2nd or 3rd parameters. This may not invalidate the client area this way.

+3
source

Actually, this does the trick:

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

Source: https://habr.com/ru/post/1309571/


All Articles