constant WM_PAINT messages
-
I am trying to override the WM_PAINT message and I am continuously getting WM_PAINT messages. The basic code snippet is: protected override void WndProc(ref Message m) { if (m.Msg == WM_PAINT) { Trace.WriteLine(" WM_PAINT event"); m.Result = IntPtr.Zero; } else { base.WndProc(ref m); } } As I am planning to do all the drawing I don't want to call the base message processing for the WM_PAINT messages. Any ideas?
-
I am trying to override the WM_PAINT message and I am continuously getting WM_PAINT messages. The basic code snippet is: protected override void WndProc(ref Message m) { if (m.Msg == WM_PAINT) { Trace.WriteLine(" WM_PAINT event"); m.Result = IntPtr.Zero; } else { base.WndProc(ref m); } } As I am planning to do all the drawing I don't want to call the base message processing for the WM_PAINT messages. Any ideas?
your code looks fine to me, could you be more specific about your problem? I hope you understand... By the way... visit http://nehe.gamedev.net[^]
-
your code looks fine to me, could you be more specific about your problem? I hope you understand... By the way... visit http://nehe.gamedev.net[^]
I probablly should have mentioned that this is for a toolbar control that only contains buttons.. It seems that when I call the base message processing I only get the one WM_PAINT message (for instance when the cursor is dragged over a button). If I don't call the base message processing I constantly get WM_PAINT messages.
-
I am trying to override the WM_PAINT message and I am continuously getting WM_PAINT messages. The basic code snippet is: protected override void WndProc(ref Message m) { if (m.Msg == WM_PAINT) { Trace.WriteLine(" WM_PAINT event"); m.Result = IntPtr.Zero; } else { base.WndProc(ref m); } } As I am planning to do all the drawing I don't want to call the base message processing for the WM_PAINT messages. Any ideas?
WM_PAINT
is sent for many reasons, and the best way to optimize your code is to honor thePaintEventArgs.ClipBounds
property passed toOnPaint
. Only draw what's necessary. OverridingWndProc
to handle painting is almost never the right way to handle user painting. Instead, you callSetStyle
in the constructor and overrideOnPaint
like so:public MyControl()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint,
true);
// ...
}
// ...
protected override void OnPaint(PaintEventArgs e)
{
// ...
// Call or don't call base.OnPaint(e) depending on the circumstances
}Control.WndProc
already handles theWM_PAINT
messages and wraps the arguments necessary for painting in thePaintEventArgs
and disposes theGraphics
object whenOnPaint
returns. If you want double-buffering for your custom drawing code, also OR theControlStyles.DoubleBuffer
enumeration withSetStyle
in the example source above. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
I probablly should have mentioned that this is for a toolbar control that only contains buttons.. It seems that when I call the base message processing I only get the one WM_PAINT message (for instance when the cursor is dragged over a button). If I don't call the base message processing I constantly get WM_PAINT messages.
WM_PAINT methods are handled differently than other messages by Windows. A WM_PAINT message is automatically sent if there are any outstanding invalid regions in your window. Windows knows that have painted your window, and thus stop sending WM_PAINT, after an application calls the Win32 functions BeginPaint\EndPaint. The easiest way to accomplish this in your case is by calling the base class OnPaint, which handles it for you.