[RESOLVED] Calling default in OnNcPaint defore my painting paints over mine?
Okay, this is been bugging me for the past couple of days. I'm overriding OnNcPaint to do my own caption painting (in a dialog box). If I call "Default" before I do my painting, the default caption and borders remain (as if I'm not painting at all). If I comment out my call to "Default", my caption looks great, but I get no menu bar (yep, I have a menu on the dialog). If I call "DrawMenu" before or after painting, the dialog is all screwed up (and there is no painting in the nonclient area).
Any ideas on what I might have missed? I'm running VS2012, on Windows 7.
Viggy
Re: Calling default in OnNcPaint defore my painting paints over mine?
I would try to paint your stuff first and remove the painted area from the update region, then call default.
Re: Calling default in OnNcPaint defore my painting paints over mine?
Hmmm, that doesn't seem to be working. In looking at the bounding box for the update region, it looks like it's in client coords, it doesn't include the nc area. In testing (using ValidateRgn), the nc area isn't affected...
Viggy
Re: Calling default in OnNcPaint defore my painting paints over mine?
Interesting. From the MSDN:
Quote:
The system maintains an update region for the nonclient area. When an application receives a WM_NCPAINT message, the wParam parameter contains a handle to a region defining the dimensions of the update region.
Since I'm working in MFC, I don't get the wParam argument for my override (I'm handling NC painting in the "OnNcPaint" function). Any idea on how to get the handle to this region from the window? I'm not finding anything in the MSDN. :(
Viggy
1 Attachment(s)
Re: Calling default in OnNcPaint defore my painting paints over mine?
Okay, I've attached an example of what I'm trying to do. Build and run the program, and notice that the menu isn't drawn (until you hover the mouse over it). Comment out the "Default()" calls in my "OnNcPaint" and "OnNcActivate" overrides, and all my work goes away!
Viggy
Attachment 31551
Re: Calling default in OnNcPaint defore my painting paints over mine?
Quote:
Originally Posted by
MrViggy
Interesting. From the MSDN:
Since I'm working in MFC, I don't get the wParam argument for my override (I'm handling NC painting in the "OnNcPaint" function). Any idea on how to get the handle to this region from the window? I'm not finding anything in the MSDN. :(
Viggy
I always used CWnd::GetCurrentMessage()
Will play with your test case.
Re: Calling default in OnNcPaint defore my painting paints over mine?
Quote:
Originally Posted by
MrViggy
Okay, I've attached an example of what I'm trying to do. Build and run the program, and notice that the menu isn't drawn (until you hover the mouse over it). Comment out the "Default()" calls in my "OnNcPaint" and "OnNcActivate" overrides, and all my work goes away!
Viggy
I might be wrong, but I don't see where you handle WM_NCCALCSIZE message.
How does the window know that a part of its client area is painted as a non-client?
Re: Calling default in OnNcPaint defore my painting paints over mine?
I tried handling the WM_NCCALCSIZE message, but nothing inside the client area was being painted. I set the rectangles to the coords of the client area.
I'll give it another shot...
Thanks!
Viggy
Re: Calling default in OnNcPaint defore my painting paints over mine?
My point is - you shouldn't paint client area in WM_NCPAINT, as it will be clipped out.
Re: Calling default in OnNcPaint defore my painting paints over mine?
Correct. I'm not, really. The code excludes the client area from the clipping region, so I don't have to worry about "accidentally" drawing in the client region.
Also, in reading the MSDN, the WM_NCCALCSIZE tells the system what the valid client area is. My non-client area is the same as the system defaults, so I don't think I need to handle this message...
Viggy
Re: [RESOLVED] Calling default in OnNcPaint defore my painting paints over mine?
Okay, I finally found one solution to my problem (there may be others). Before I do my painting, I can call the default window proc, passing in a nonclient region that is only the menu area:
Code:
CRect rc;
GetWindowRect(rc);
rc.top = rc.top + ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CYCAPTION);
rc.bottom = rc.top + ::GetSystemMetrics(SM_CYMENU);
rc.left += ::GetSystemMetrics(SM_CXSIZEFRAME);
rc.right -= ::GetSystemMetrics(SM_CXSIZEFRAME);
HRGN hRgnCaption = ::CreateRectRgnIndirect(&rc);
DefWindowProc(WM_NCPAINT, (WPARAM)hRgnCaption, NULL);
DeleteObject(hRgnCaption);
Thanks for the suggestions!
Viggy