Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if win32 c++ application lost focus after CTRL-ALT-DEL?

Tags:

c++

focus

winapi

I've written a win32 App in C++ (a game) and I want to be able to know if the application has lost focus due to the user pressing CTRL-ALT-DEL and starting the task manager. How can I do this? What I want to do after detecting the event is to minimize the window of my game and pause its processing (animations, audio, etc.). However, if the user returns from the CTRL-ALT-DEL menu to the game then it should keep running as usual. I've thought that I could check for key presses on CTRL, ALT and DEL but that doesn't seem to work and just reacting to the lost the focus (WM_KILLFOCUS) is not what I want.

like image 674
nairdaen Avatar asked Apr 16 '15 08:04

nairdaen


1 Answers

You can use WTSRegisterSessionNotification(), you'll get the WM_WTSSESSION_CHANGE message when the user presses Ctrl+Alt+Del and switches to the secure desktop.

Beware that you cannot tell that it was actually the secure desktop that he switched to, that would be rather nasty security leak. You'll also get the notification when he switches to another logon session. Also a case where you want to stop your game of course.

For that matter, a game ought to automatically pause whenever the game window loses the foreground. Nobody likes to be killed when they switch to their email reader :) Use the WM_ACTIVATEAPP message

like image 170
Hans Passant Avatar answered Nov 10 '22 20:11

Hans Passant