Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does overriding OnNcPaint() affect the painting of the client area of a window?

I want to change the appearance of a window's caption bar, so I decided to override the OnNcPaint() method of CMainFrame. But when I did this, I found a problem. If there is another window covering my window, and I drag the window quickly, the content of the client area of my window disappeared, which came to sight only when I stopped the dragging.

My overridden OnNcPaint() is like below:

void CMainFrame::OnNcPaint()
{
    CDC* pWinDC = GetWindowDC();
    //do some drawing
    ReleaseDC(pWinDC);
}

Is there something wrong with my approach? Thank you!

like image 297
user26404 Avatar asked Jan 26 '26 01:01

user26404


1 Answers

Unless you use a clipping region set up to exclude the client area, you can paint over it from OnNcPaint(). So... if your drawing logic can't be modified to exclude the client in some other way, set up an appropriate clipping region first:

CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.OffsetRect(-rect.left, -rect.top);
rect.OffsetRect(-rect.left, -rect.top);
pWinDC->ExcludeClipRect(&rectClient);
// ...
// draw stuff here
// ...
pWinDC->SelectClipRgn(NULL);
like image 128
Shog9 Avatar answered Jan 27 '26 14:01

Shog9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!