kero
kero

Reputation: 736

MessageBox & WM_TIMER (after Win2k)

Everyone here knows that from WinXP to user32.dll appeared MessageBoxTimeout API.

But now it's not about using undocumented MessageBoxTimeout, but the use of a documented MessageBox:

so here's a coincidence that from WinXP for any MessageBox - PostMessage (WM_TIMER, 0,0) is equivalent to PostMessage (WM_CLOSE, 0,0).

Question to insiders MS: this is a bug or a feature?

Upvotes: 2

Views: 377

Answers (1)

David Heffernan
David Heffernan

Reputation: 612824

It's not a coincidence. It turns out that MessageBox is implemented by a call to MessageBoxTimeout which passes a timeout value of 0xFFFFFFFF. This is trivial to discern using a debugger. And it also turns out that MessageBoxTimeout dialogs respond to WM_TIMER messages by closing the dialog. That's how MessageBoxTimeout implements the timeout.

So, if you post a WM_TIMER message to a MessageBox dialog you are really posting it to a MessageBoxTimeout dialog and so you will indeed close it.

It's certainly not a bug because MessageBox makes no promises at all as to how it will respond to receiving WM_TIMER messages. And it's not a feature because it's not documented. It's just a curious side-effect of the current implementation of MessageBox.

Of course, all this is implementation detail, subject to change, etc. etc.

Upvotes: 3

Related Questions