window remains active

This is a discussion on window remains active within the Windows Programming forums, part of the Platform Specific Boards category; I'm game runs in a window and remains active when it's not in the foreground. For example let say I ...

window remains active

I'm game runs in a window and remains active when it's not in the foreground. For example let say I have notepad on top of my game. My game will still proceed as normal. How do I make it pause. From searching this probabley has to do with using PeekMessage instead of GetMessage, correct? GetMessage sleeps when there are not messages ,while PeekMessage is awake even when there aren't any messages.

Get yourself a global BOOL variable and set it to TRUE (Global is the simplest way unless you have another option). In your message loop, set an if that only checks for messages and processes game logic when the variable is TRUE.

Then create a handler for WM_SETFOCUS & WM_KILLFOCUS and set the variable as false when you lose focus and true when you have it.