Why does the overridden non-client area show the default value when the window loses focus on win32?

I have an overridden non-client area of ​​my window in the window callback function as follows:

case WM_NCPAINT: { HDC hdc; RECT rect; HPEN pen; hdc=GetDCEx(hWnd,(HRGN)wParam,DCX_WINDOW|DCX_CACHE|DCX_INTERSECTRGN|DCX_LOCKWINDOWUPDATE); GetWindowRect(hWnd,&rect); pen=CreatePen(PS_SOLID, 10, RGB(255, 0, 0));//red pen 10 pixels in size SelectObject(hdc,pen); Rectangle(hdc,0,0,(rect.right-rect.left),(rect.bottom-rect.top)); DeleteObject(pen); ReleaseDC(hWnd,hdc); RedrawWindow(hWnd,&rect,(HRGN)wParam,RDW_UPDATENOW) }break; 

What the trick does is, and in the example above, draws a red rectangle around my window. However, if the window loses focus, then by default the non-client area is colored, and my custom drawing of the non-client area disappears.

I tried to catch the WM_KILLFOCUS message in my window callback function and did the same with it as with WM_NCPAINT, but did nothing (although I saw that I get this message when I click on another window and my loss window).

What am I missing here ...?

+6
source share
1 answer

Add handler for WM_NCACTIVATE :

 case WM_NCACTIVATE: // Paint the non-client area now, otherwise Windows will paint its own RedrawWindow(hWnd, NULL, NULL, RDW_UPDATENOW); break; 
+5
source

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


All Articles