Reputation: 8354
I'm doing custom handling of WM_PAINT and WM_ERASEBKGD in the WndProc override in a Control.
protected override void WndProc(ref Message m)
{
if (m.Msg == 0xF)
{
// [Draw using stored hDC]
m.Result = (IntPtr)1;
}
else if (m.Msg == 0x14)
{
m.Result = (IntPtr)1;
}
else
base.WndProc(ref m);
}
It works fine except that it is called constantly, about 300 times a second, and if I allow the base to handle it, it is called once. What am I leaving out?
Upvotes: 3
Views: 4291
Reputation: 941317
This happens because you haven't told Windows that the "dirty rectangle" is no longer dirty and was painted. So it keeps generating WM_PAINT messages.
This is normally done with BeginPaint/EndPaint(), called by the default message handler built into .NET. Which calls the virtual OnPaint() method. Overriding it, or handling the Paint event, is the recommended way. If you don't want to use this for some reason then you'll have to pinvoke ValidateRect().
Upvotes: 5