Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Splat

Best way to track window focus

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

The only thing I can come up with is either WM_ACTIVATEAPP or WM_CANCELMODE. Or do these messages get sent (paired) with a WM_ACTIVATE message?

Why are you checking it twice (bit manipulation is not my specialty yet)?

Wish I could have suggested something better!

Share this post


Link to post
Share on other sites
Advertisement
Well, the above code is a combination of documentation and analysis. The reason to check wParam twice is because it contains two pieces of data: one in the low word and one in the high.

Experimentally, this works in all cases. But I really need confirmation because this is really a hack and does not make much logical sense in the context of the MSDN docs.

- Splat

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I would use the WM_ACTIVATEAPP message, when there is about to be a change in the window focus, this message is sent to the app who of the window that will loose focus and to the app of the window that will gain it.
wParam will be equal to TRUE if it is the window gaining focus or FALSE if its loosing it. lParam contains the thread ID of the app that owns the window that will gain focus. That is pretty much what is said in the MSDN Library.

Share this post


Link to post
Share on other sites
Been playing with this a bit, and the best I can come up with is using the WM_ACTIVATE message and this code:

if ((wParam & 0xffff) == WA_INACTIVE) {
isActive = false;
}
else {
if ((wParam >> 16) == 0)
isActive = true;
}

Anyone have any suggestions? This seems to work in all circumstances, but there may be something I am overlooking.

- Splat

Share this post


Link to post
Share on other sites
That was what I had originally, but it fails to detect special cases with minimizing the application. Mainly it will not detect the deactivation if it's task bar box is clicked to minimize it (i think, the old code is now only in the SourceSafe database). Simply, it didn't work all the time. What I have above works all the time, but I've only tested on Win2000. Which is certainly not my target audience.

- Splat

Share this post


Link to post
Share on other sites

  • 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!