• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Norman Barrows

What windows messages should a well behaved app support?

15 posts in this topic

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. :)

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

looks like at a minimum, WM_DESTROY should be handled: close_myapp() PostQuitMessage() Exit()

 

i had it turned off, and the process would not terminate from the taskbar when its window was destroyed.

 

Turning it on and just calling PostQuitMessage() only unhooks the winproc, its doesnt exit. 

 

close_myapp() is the "right" way to do it, but may be overkill, as you're terminating anyway, and windows ought to release all resources associated with the process. but its still probably safer to not rely on windows to do your cleaning up for you.    in my book (my way of doing things) i'd probably have to call "not calling close_myapp()" a bad practice.

 

other than WM_DESTROY, i only trap mouse movement, buttons, and wheel. default winproc does all the rest.  i wonder what happens when the PC goes to sleep when the game is running? never tried it.   it handles lost device now, so it ought to come right back up when you wake up the PC, assuming it (windows) does a full save and restore of state on sleeping.

0

Share this post


Link to post
Share on other sites

Does anyone know which messages are sent when switch display shortcuts are used: shift + win + left/right arrow keys?

0

Share this post


Link to post
Share on other sites

i wonder what happens when the PC goes to sleep when the game is running? never tried it.   it handles lost device now, so it ought to come right back up when you wake up the PC, assuming it (windows) does a full save and restore of state on sleeping.

You can easily test this.  First, create a timer that times out after a short time, using SetTimer().  When you receive WM_TIMER, call KillTimer(), then call SetSuspendState() to make the system sleep, passing FALSE for all three arguments.  According to MSDN, calling SetSuspendState() on you UI thread is a blocking call, which means you should be able to invoke your recovery code right after.

 

EDIT: An alternative method is to do sleep manually, then handle the WM_POWERBROADCAST notification when the system awakens.

Edited by shuma-gorath
0

Share this post


Link to post
Share on other sites

Does anyone know which messages are sent when switch display shortcuts are used: shift + win + left/right arrow keys?

 

none specific to that action that i can tell. and i just dug through them all the other day. if you're talking about windows itself, they may trap the individual WM_key messages or check the keys asynchronously  if you're talking about 3rd party software it may be an application defined message.

 

i would think that it would send some type of message about change of window size or something. you're talking about switching between 2 monitors on a multi-monitor system, right?

0

Share this post


Link to post
Share on other sites

Does anyone know which messages are sent when switch display shortcuts are used: shift + win + left/right arrow keys?

 

none specific to that action that i can tell. and i just dug through them all the other day. if you're talking about windows itself, they may trap the individual WM_key messages or check the keys asynchronously  if you're talking about 3rd party software it may be an application defined message.

 

i would think that it would send some type of message about change of window size or something. you're talking about switching between 2 monitors on a multi-monitor system, right?

 

Yep, for some reason my win app (CreateWindow, etc...) doesn't switch to other monitor.

0

Share this post


Link to post
Share on other sites

Yep, for some reason my win app (CreateWindow, etc...) doesn't switch to other monitor.

 

2 head system, right?      2 graphics cards, 2 monitors,     or 2 cards in 1 with 2 monitors.

 

i would think that each head would be a separate d3d device, and that you'd shut down one and startup the other on head switch.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0