Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Message for User Locking Screen

I'm working with old-school windows programming in C++, and I need to capture an event in my WndProc which indicates that the user has logged off or locked the screen.

update (thanks David Hefernan) I've searched everywhere, but the only thing I've found is the WM_ENDSESSION message - which does not handle screen lock events.

Anyone know what how this is done? I need to apply it to Windows 2000 through Windows XP flavors.

like image 360
Brent Arias Avatar asked Feb 24 '23 21:02

Brent Arias


1 Answers

The solution is to register for the WM_WTSSESSION_CHANGE and respond to it in your WndProc.

According to the documentation of WM_WTSSESSION_CHANGE, the minimum supported OS is XP. Now, the since Windows 2000 is no longer supported, the documentation often says XP is the minumum when in fact the functionality is available on earlier versions. In this case, a quick web search suggests that you may be disappointed.

To be notified about session logoff (rather then the screen lock), you should be able to use the lParam value of the WM_ENDSESSION message. Look for the presence of the ENDSESSION_LOGOFF flag.

like image 123
David Heffernan Avatar answered Feb 27 '23 12:02

David Heffernan