Handle Windows lock/unlock events in wxWidgets Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
sw
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sat Mar 16, 2019 8:09 pm

Handle Windows lock/unlock events in wxWidgets

Post by sw » Thu Jan 09, 2020 2:04 pm

Hi all :D

I have been unable to find any information about handling Windows lock and unlock events (i.e. pressing 'Win' + 'L')

As far as I can tell, it seems wxWidgets only has a event for a session ending (wxEVT_END_SESSION) which to my understanding is closing the app or logging off.

Windows does have events that get fired when a user locks and unlocks a PC.

I understand you need to call this function WTSRegisterSessionNotification https://docs.microsoft.com/en-za/window ... dfrom=MSDN and then handle a WM_WTSSESSION_CHANGE message https://docs.microsoft.com/en-za/window ... ion-change

I am specifically interested in these events:
WTS_SESSION_LOCK (0x7)

The session identified by lParam has been locked.

WTS_SESSION_UNLOCK (0x8)

The session identified by lParam has been unlocked.
Since it seems wxWidgets does not cater for these events, how can I hook into the wxWidgets event loop to process these messages (events)? Or if you direct to a blog post or wiki page. My Google-fu was not able to find anything relating to this...

User avatar
doublemax
Moderator
Moderator
Posts: 14630
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Handle Windows lock/unlock events in wxWidgets

Post by doublemax » Thu Jan 09, 2020 2:22 pm

Override MSWWindowProc in your main frame.

Here's some sample code that i use to detect USB device connects/disconnects:

Code: Select all

WXLRESULT mainFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
  if( nMsg==WM_DEVICECHANGE )
  {
    wxLogDebug(wxT("WM_DEVICECHANGE %x %x"), wParam, lParam);
    if( wParam==DBT_DEVICEARRIVAL || wParam==DBT_DEVICEREMOVECOMPLETE )
    {
        // handling here
    }
  }

  return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
}
Use the source, Luke!

Post Reply