views:

84

answers:

2

I have an game application I have written for Windows Mobile and I want to have a timer associated with the puzzle. If the program loses focus for any reason (call comes in, user switches programs, user hits the Windows button) then I want a pop up dialog box to cover the puzzle and the timer to stop. When the user closes the pop up dialog the timer can start up again.

Does anyone know how to do this?

Thanks

A: 

A quick way would be to use PInvoke to call GetForegroundWindow() and GetWindowText() whenever your timer ticks (once a second?).

GetForegroundWindow() returns a windows handle which you can use to call GetWindowText(). If the text of the foreground window matches your form's Text property (its caption), you know your app has the focus. You can then show or hide your puzzle in each timer tick.

MusiGenesis