Archived

This topic is now archived and is closed to further replies.

romer

Question about InvalidateRect

Recommended Posts

Tonight I was trying to find out how I could cause a WM_PAINT message be sent to my program so that my window would be repainted after I update one of the data structures, and I stumbled across the InvalidateRect function. It does the job fine right now, but I was just wondering will it always post a WM_PAINT message in the message queue for processing, or is that for only certain cases? Also, a bit of an aside, what are some practical uses for the UpdateWindow function other than using it right after window creation? Could it be used in place of InvalidateRect?

Share this post


Link to post
Share on other sites
quote:
Original post by MRom
will it always post a WM_PAINT message in the message queue for processing, or is that for only certain cases?


invalidaterect doesn''t directly cause WM_PAINT to be posted. it merely tells windows that a window or part of one needs to be repainted. if the application doesn''t do anything, WM_PAINT will be posted once the message queue is empty, and window will be redrawn. if you, for instance, call ValidateRect immediately after InvalidateRect, you won''t get WM_PAINT.
quote:

Also, a bit of an aside, what are some practical uses for the UpdateWindow function other than using it right after window creation? Could it be used in place of InvalidateRect?

you can use them together to ensure timely updates of your window. WM_PAINT will be posted and processed whenever there are no other messages pending in your queue, and that may take some time. if, however, you call InvalidateRect and immediately after that call UpdateWindow, your window will be updated regardless of how many messages are in your message queue.

or you can use RedrawWindow to achieve the same result.

Share this post


Link to post
Share on other sites