Jump to content
  • Advertisement
Sign in to follow this  

How do I detect and act upon an app losing focus?

This topic is 4397 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

OK, next step on my way to being the ultimate newb programmer.. Using Allegro.. I looked through its manual and didnt see a whole lot. A search on the boards here seems to return a lot of results dealing with directx and direct input. If I have my app in windowed mode or even full screen and the user alt-enters or alt-tabs, how do I go about detecting if the application has lost focus, so that I can pause the game?

Share this post


Link to post
Share on other sites
Advertisement
It will be a WM_SOMETHING message sent to the window. Dont know about using Allegro, but if you have a WndProc CALLBACK function, there WILL be a message that is sent. I'm trying to find the message now but no luck, will post again if I find something

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The Windows message is WM_ACTIVATE. And you will get it in your winproc update loop.

The lower half of wParam is if you are deactived or activated, and its seems these days it will tell you if it was done by the mouse as well.
So to see if you where activated you would do
switch( Message.ID )
{
case WM_ACTIVATE:
{
if( WA_ACTIVE == LOWORD( wParam ) ||
WA_CLICKACTIVE == LOWORD( wParam ) )
{
//I just became activated
}
else if( WA_INACTIVE == LOWORD( wParam ) )
{
//I just became deactivated.
}
}
break;
}


For full details check it out on msdn here. Or find a copy of Petzold's Windows Programming book.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_activate.asp

Share this post


Link to post
Share on other sites
Now I have seen examples of how to catch this using normal windows programming and GDI I think it is.

In this case, Im using allegro and c++ and I have yet to see an allegro example that caught windows messages. I was hoping that there was a library or an allegro function somewhere that would allow me to trap this event while maintaining the ability to be platform independant.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!