winapitimermessage-queuewindows-messages

How does Windows accumulate WM_TIMER messages?


As I understand it, WM_PAINT messages are not generated when a function like InvalidateRect is called; rather an object that can be be thought of as a flag containing some info about the dirty region is set, and when the other messages in the queue are handled, a single WM_PAINT message is generated which combines the regions from all flags since the last successful WM_PAINT message. Presumably this is done once per HWND associated with a particular thread

I'm wondering how WM_TIMER messages are accumulated? I thought perhaps only the most recent flag for each thread would be kept, but what if different TIMERPROCs and window handles have different timers. What if two SetTimer calls with different intervals point to the same window handle; will one WM_TIMER be generated for each timer ID?


Solution

  • What if two SetTimer calls with different intervals point to the same window handle; will one WM_TIMER be generated for each timer ID?

    Yes, there will be one message generated for each distinct timer.

    You explicitly state "with different intervals". But this is not a factor. What matters is timer identity, defined by the timer ID. You can have multiple distinct timers with the same interval.

    What can happen is that timer events can coalesce if the message queue is not serviced as frequently as the events are logically generated. So if multiple timer intervals elapse between calls to pump the message, only a single timer message is generated. Don't think of timer events as indicating how much timer has elapsed, rather treat them as indicating that at least the specified interval has elapsed.