Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. constant WM_PAINT messages

constant WM_PAINT messages

Scheduled Pinned Locked Moved C#
graphicsdebuggingquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jcl555
    wrote on last edited by
    #1

    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?

    S H 2 Replies Last reply
    0
    • J jcl555

      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?

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      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[^]

      J 1 Reply Last reply
      0
      • S Stanciu Vlad

        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[^]

        J Offline
        J Offline
        jcl555
        wrote on last edited by
        #3

        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.

        B 1 Reply Last reply
        0
        • J jcl555

          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?

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          WM_PAINT is sent for many reasons, and the best way to optimize your code is to honor the PaintEventArgs.ClipBounds property passed to OnPaint. Only draw what's necessary. Overriding WndProc to handle painting is almost never the right way to handle user painting. Instead, you call SetStyle in the constructor and override OnPaint 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 the WM_PAINT messages and wraps the arguments necessary for painting in the PaintEventArgs and disposes the Graphics object when OnPaint returns. If you want double-buffering for your custom drawing code, also OR the ControlStyles.DoubleBuffer enumeration with SetStyle 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]

          1 Reply Last reply
          0
          • J jcl555

            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.

            B Offline
            B Offline
            Brian Nottingham
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups