How to update only part of a window

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to update only part of a window

    I need to update a section of a window at a high framerate, the reason being that building the whole screen is taking too long.
    Is InvalidateRect what I need to use for this?
    How does this work, does it build the whole screen but only update the rectangle requested? Or does it build only that section of screen (reducing time to build) and update it?
    How do people use PREPAINT? I was clearing the screen in prepaint but if I do that and only update a section of the screen, only that section of the screen will be visible?
    Thanks.
  • Hello,

    The messages WM_PRE_PAINT and WM_POST_PAINT are not meant for drawing operations. They are just to be able to perform actions right before and right after a window is drawn. This might be useful, since windows might receive more than one WM_PAINT event for being drawn once.

    WM_InvalidateRect() is the proper function to use. Please note that the rectangle is sent along with the message WM_PAINT, so you can determine which items to draw in order to improve performance.

    Best regards,
    Adrian
  • Thanks Adrian!


    I am finding that InvalidateRect is working well - even without determining which items to draw, it results in a big improvement to performance. Can you explain why this is? Is it doing something to avoid drawing things that fall out of the invalidated area? If so, does using the rectangle information in WM_PAINT result in a meaningful improvement on top of that?

    Also, why would a window receive more than one WM_PAINT event? I know multiple invalidates can lead to one WM_PAINT, but not sure why multiple WM_PAINTs would happen.
    What is the grouping that is bounded by the pre and post paint messages?

    Thanks for your help!