I have a overridden the non-client area of my window, in the window's 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;
That does the trick and in the case above draws a red rectangle around my window. However, if the window loses focus, then the default non-client area is painted and my custom non-client area drawing disappear.
I have tried catching the message WM_KILLFOCUS in my window's callback function and do the same with it as I do with WM_NCPAINT but it didn't do anything (although I saw I receive this message when I press on another window and my window losses focus).
What am I missing here...?
Add a 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With