What windows messages should a well behaved app support?

Started by
14 comments, last by Norman Barrows 11 years ago

What windows messages should a well behaved app support?

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Advertisement

Precisely those messages needed to do its job - no more, no less.



Ask a vague question, get a vague answer :-P

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Precisely those messages needed to do its job - no more, no less.



Ask a vague question, get a vague answer :-P

Agree'd, but I think pointing out a couple of the non-obvious ones you want to consider would be good:

WM_SYSKEYDOWN, specifically VK_MENU. In some fullscreen windows if the user hits alt it can hang the program for no apparent reason. The user just needs to hit alt again or esc but this is just bad to allow it to happen.

WM_SYSCOMMAND, specifically SC_SCREENSAVE. Letting the screen saver kick in is also bad form in a fullscreen app.

WM_DISPLAYCHANGE, often overlooked but in multimonitor setups you need to notice this if your app were on say the second monitor and the user hit Windows-P and changed to mirroring, if they have 2 different resolution monitors your full screen app could be forced into a different resolution. DX would trigger a device lost or reset I believe but a GL game needs to catch this and readjust view areas and all that.

The various CPU frequency change messages, power notifications (sleep/hibernate/etc) and related. You may not care about the CPU change but your app should respect sleep/hibernate and say disconnect from servers and/or go to a menu and wait for wakeup etc.

Hmm, I remember there being a number more of these annoying edge cases you really should handle but can't think of any more off the top of my head.

A few others.

WM_MENUCHAR for reasons outlined at http://stackoverflow.com/questions/3662192/disable-messagebeep-on-invalid-syskeypress

WM_INPUT if you're using raw input (obviously).

WM_MOVE and WM_SIZE are good places to handle any internal state you may have that depends on the window size and position. WM_SIZE is not a good place for lost device handling, nor is WM_ACTIVATE.

WM_CLOSE may be handy to prevent the player from accidentally closing the window when they may not intend to.

WM_ACTIVATE to detect when you're no longer the focus; this is useful because you can start Sleeping, skip display updates and otherwise behave like a civilized program on the player's computer. Don't use it for lost device handling.

WM_DESTROY can be a good place to clean up resources.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

A few others.

WM_MENUCHAR for reasons outlined at http://stackoverflow.com/questions/3662192/disable-messagebeep-on-invalid-syskeypress

WM_INPUT if you're using raw input (obviously).

WM_MOVE and WM_SIZE are good places to handle any internal state you may have that depends on the window size and position. WM_SIZE is not a good place for lost device handling, nor is WM_ACTIVATE.

WM_CLOSE may be handy to prevent the player from accidentally closing the window when they may not intend to.

WM_ACTIVATE to detect when you're no longer the focus; this is useful because you can start Sleeping, skip display updates and otherwise behave like a civilized program on the player's computer. Don't use it for lost device handling.

WM_DESTROY can be a good place to clean up resources.

Those are good messages to handle but only the menu one is the type of edge case stuff I was thinking of. Not saying this is wrong, just that I'd be more interested in getting a good list of all those rarely used but oh so annoying messages a game should handle but usually doesn't. As much for the original poster as for me, I used to have a list but I can't seem to find the damned thing. :)

According to the Windows 7 logo certification guidelines, which define what Microsoft thinks is a well behaved app, all applications must handle WM_QUERYENDSESSION and WM_ENDSESSION.

More info here:
http://download.microsoft.com/download/1/E/9/1E9580D9-2B2B-499C-918A-C9BA5EAC4A32/Windows%207%20Client%20Software%20Logo.pdf

Precisely those messages needed to do its job - no more, no less.


Why even answer if that's all you have to say?

You can choose to handle all or none.

Most important is that you pass ALL of them on to DefWindowProc unless you explicitely handle it and the docs say you can return a specific value from your WndProc.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Precisely those messages needed to do its job - no more, no less.


Why even answer if that's all you have to say?

Because it's really correct. An open-ended question like that implies that the author is either not thinking about the question or else is not thinking about solutions.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Precisely those messages needed to do its job - no more, no less.


Why even answer if that's all you have to say?

Actually his answer sums up a strategy which is important in order to not introduce unwanted quirks. The less messages that a window handles, the less likely it is to misbehave. DefWindowProc() does A LOT of things to implement standard behavior of windows, and it expects to receive certain messages with certain data in a certain order. If your window messes with the order (by calling certain functions in its message handler which cause certain events which will in turn send certain messages before they return, or by not passing certain messages to DefWindowProc()), then there is a chance your window will break one of the standard behaviors implemented by DefWindowProc().

So yes, only process the messages that you need to process.

Hmm, I remember there being a number more of these annoying edge cases you really should handle but can't think of any more off the top of my head.

thanks for the list. i think i've figured out the absolute minimum. those you mentioned will make for a more robust implementation.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement