Reputation: 5282
I am currently developing a kind of "WinMerge" clone, and currently I am trying to implement a custom scrollbar which should later represent both compared files as a rectangle in the background each.
This is what it looks like at the startup:
However, after scrolling around a little bit, this is what I end up with:
As you can clearly see, only those parts look correct which I explicitely paint over in my paint routine:
void LocationPane::OnPaint(CDCHandle dc)
{
DefWindowProc();
dc = GetDC();
DrawLocationPaneFigures(dc);
}
This is how my control is configured in my .rc file:
CONTROL "",IDC_LOCATIONPANE,"Static",SS_OWNERDRAW | SS_NOTIFY | WS_BORDER | WS_GROUP,7,21,91,541
As you can see, it is an owner drawn control.
How can I erase the background for this control while repainting it?
Upvotes: 0
Views: 340
Reputation: 27756
A static control with SS_OWNERDRAW
style receives a WM_DRAWITEM
message when it needs to be redrawn.
So first you need to replace your OnPaint()
handler by a handler for WM_DRAWITEM
. Instead of calling GetDC()
use the device context supplied to you in the DRAWITEMSTRUCT
.
To erase the background it's generally best to do it as part of the regular painting code to reduce flickering (by calling FillRect()
for instance).
I suggest to always draw the whole client area of your control. Then you may handle WM_ERASEBKGND
to return TRUE
without calling DefWindowProc()
to reduce flickering even more.
Upvotes: 1