UpdateWindow - Where do the WM_PAINT messages come from?

Started by raleeper, August 08, 2011, 02:43:09 AM

Previous topic - Next topic

raleeper

A mystery.  Cleaning out some old junk from my program, I came accross an invoke UpdateWindow,hwnd in my WinMain procedure.  Thinking it should not be there, I commented it out.  The program worked (works) fine without it.

But then I found that my program doesn't contain that call anywhere else.  So it seems superfluous.

But then what tells windows to send a WM_PAINT message?  The SDK help gives no indication that InvalidateRect does this, but I suspect that it does.

Is my suspicion correct, or is something else going on?

Thanks, ral

qWord

The message is sent by the system, if there is an invalidated region. Invalidation can be caused by the system (window creation, moving, sizing, ...), by other applications (e.g. if the whole Desktop gets invalidated) or explicit by your code. Normally you application validates  the region with BeginPaint and then draw the requested rectangle (PAINTSTRUCT.rcPaint) to the screen.
UpdateWindow() simply sends a WM_PAINT message directly to the window procedure, if there is an invalidate region- After a call to UpdateWindow, it is ensured that the window/control is visible to the user - otherwise the window/control may be incompletely drawn until the system send the WM_PAINT message.
FPU in a trice: SmplMath
It's that simple!

raleeper

Quote from: qWord on August 08, 2011, 06:06:29 AM
The message is sent by the system, if there is an invalidated region. Invalidation can be caused by the system (window creation, moving, sizing, ...), by other applications (e.g. if the whole Desktop gets invalidated) or explicit by your code. Normally you application validates  the region with BeginPaint and then draw the requested rectangle (PAINTSTRUCT.rcPaint) to the screen.
UpdateWindow() simply sends a WM_PAINT message directly to the window procedure, if there is an invalidate region- After a call to UpdateWindow, it is ensured that the window/control is visible to the user - otherwise the window/control may be incompletely drawn until the system send the WM_PAINT message.

I see.  InvalidateRect is one of various things that can invalidate a region and so cause the system to send WM_PAINT.

Thank you, qWord.

Tedd

Just to add: WM_PAINT is only generated when your message queue is empty AND there is at least one update region.
So, if there are still messages in your queue, the regions won't be redrawn until those have been processed. If more messages arrive in the meantime, that will put off the update even longer.
No snowflake in an avalanche feels responsible.

dedndave

the Invalidate/Validate functions change the update regions
(InvalidateRect, InvalidateRgn, ValidateRect, ValidateRgn)
and, as Tedd pointed out...
QuoteWM_PAINT is only generated when your message queue is empty AND there is at least one update region

however, UpdateWindow may be used to force an immediate update if there are any regions that require it

QuoteThe UpdateWindow function updates the client area of the specified window by sending a WM_PAINT
message to the window if the window's update region is not empty. The function sends a WM_PAINT
message directly to the window procedure of the specified window, bypassing the application queue. If
the update region is empty, no message is sent.

raleeper

Tedd and dedndave:

Thank you.  message queue point noted.