I'm trying to create custom non client area.
So I handled WM_NCPAINT
message in WndProc method, and try to create a Red colored Rectangle in the non client area, but I found two problems with that.
- The Rectangle I drawed in non client area also covers Client Area.
So to encounter it I added RedrawWindow
function at the end of WM_NCPAINT
message but I'm not sure its a good idea. What else I can do to correct this?
- I got some weird result on resizing window many time. I just don't know how to explain it, but I try
This is what I'm achieved so far
but if I resize it many times continuously (like 10 - 15) it gets this
the whole picture is the screenshot of the window (the first one). I don't know what is happing with it. White part is draw wrongly and right and bottom part seems like transparent, but its all the screenshot of one window. (SS by snipping tool)
All mouse clicks pass through the transparent part.
Window is resize well but nothing drawn within it correctly, not with correct size. The size of drawing is set to some maximum size (don't know what, it random).
The code is all same as the default code comes with the Windows Desktop Application C
Template of visual studio.
Just added the custom code for WM_NCPAINT
message.
case WM_NCPAINT:
{
HDC hdc = GetWindowDC(hWnd);
if (hdc) {
RECT frame = { 0 };
GetWindowRect(hWnd, &frame);
frame.right = frame.right - frame.left;
frame.bottom = frame.bottom - frame.top;
frame.left = 0;
frame.top = 0;
FillRect(hdc, &frame, CreateSolidBrush(RGB(255, 0, 0)));
ReleaseDC(hWnd, hdc);
RedrawWindow(hWnd, &frame, (HRGN)wParam, RDW_UPDATENOW);
}
return 0;
}
CodePudding user response:
IInspectable's comment helps me.
From CreateSolidBrush
: "When you no longer need the HBRUSH
object, call the DeleteObject function to delete it." You aren't doing that, and leak an HBRUSH
per WM_NCPAINT
callback. GDI resources are among the most limited resources your system has to offer.