简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM