PDA

View Full Version : Signal when computer locks



TonyInSoMD
6th February 2018, 14:43
I'm working in a Windows environment. I have a program that needs to perform a function when the computer locks, whether it's by command + L or time-out. How can I get this? In a windows forum, they gave me the suggestion to use WM_WTSSESSION_CHANGE and then wParam WTS_SESSION_LOCK in the nativeEvent. The only thing is, you have to run WTSRegisterSessionNotification first. I can't run WTSRegisterSessionNotification, because it doesn't seem to exist when I try to call it in the constructor. Is there a way to do this using Qt or does anybody know how to get nativeEvent to see it?

high_flyer
6th February 2018, 17:00
I can't run WTSRegisterSessionNotification, because it doesn't seem to exist when I try to call it in the constructor.
Amm... include the header file declaring it maybe?
(And don't forget to link against the lib defining it too)
https://msdn.microsoft.com/en-us/library/aa383841(v=vs.85).aspx

TonyInSoMD
7th February 2018, 10:53
Thanks, that's what it was, I was forgetting the #include and #pragma statements in the constructor. My only excuse is I don't deal with Windows events very much, I stick to Qt as much as possible.