Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

Handling Messages

This topic is 4112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Ive been wondering how the application can handle messages sent by windows. I know how to implement it but I'm not sure on the theory behind it. Lets say I have a simple app, maybe a small game, with a central loop that peeks/removes msgs. As I understand WinProc handles all the messages for you. And lets say i have a class camera, and it has something like HandleMessages(stuff) function. This will also work (since this is how the camera from DX SDKs works). But I'm not sure why. When a window recieves a msg, it sends it to WinProc, but how can the camera's handle messages intercept those messages, thanks.

Share this post


Link to post
Share on other sites
Advertisement
The first to receive any messages is your application itself. This is the part you mentioned which usually does PeekMessage() or GetMessage() and then subsequently calls TranslateMessage() and DispatchMessage(). The latter leads to the operating system forwarding the message to the right window (your application may have multiple).

Each window has its own WndProc() (or whatever you call it) which you must define. In its simplest form it is almost empty and simply forwards all messages to the system supplied DefWindowProc(). Normally, though, you select messages you want to receive and act on them, using something like this:

switch( message )
{
case WM_PAINT:
paint();
break;
}


This is also where you could choose to forward messages to your camera; either on specific messages or on any message if you like. For more powerful applications though, you'd best avoid the message system and do things in the main application loop. You can roughly do this like so:

while( true )
{
bool hasMessage = PeekMessage( ..., PM_NOREMOVE );
if ( hasMessage )
{
// remove it and translate/dispatch it
// ...
}
else
{
// Update scene, game state, camera, etc.
update();

// Render a frame
render();
}


Greetz,

illco

Share this post


Link to post
Share on other sites
Alight, thanks for reply so theres nothing special to it like i thought there was, i just have to forward the messages to cam inside the WndProc, thanks [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!