Link to home
Start Free TrialLog in
Avatar of suda4130
suda4130

asked on

How to find out from MFC application if the system is in the locked state (windows lock)

Is there a system level windows function that I can call from my MFC C++ application that can tell me if the system is in the locked state (Windows Lock activated).
Avatar of jkr
jkr
Flag of Germany image

You can not find that put in a direct way, but 'WTSRegisterSessionNotification()'  (http://msdn.microsoft.com/en-us/library/aa383841(VS.85).aspx) allows  you to monitor when the workstation enters the 'locked' state. You'll get a message sent to the window you register the notification for that indicates 'WTS_SESSION_LOCK', then you know that it is locked.
Avatar of suda4130
suda4130

ASKER

Jkr,

Thanks for the link... this is perfect...

How do i Locate the WndProc window procedure and add a case statement to process WM_WTSSESSION_CHANGE messages.

Can anyone attach a snippet on how to access the WndProc window
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jkr,

Thanks for the snippet. But it does not get triggered (OnSessionChange) when i lock my computer (Windows+L button)
Here is my code when i added the calls to Mainfrm.cpp

//mainfrm.h
class CMainFrame : public CFrameWnd
{
afx_msg LRESULT OnSessionChange(WPARAM, LPARAM); 
..
}
 
//mainfrm.cpp
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_SIZING()
...
 
     ON_MESSAGE( WM_WTSSESSION_CHANGE, OnSessionChange ) // necessarya entry
END_MESSAGE_MAP()
 
..
LRESULT CMainFrame::OnSessionChange(WPARAM wParam, LPARAM)
{
  if (WTS_SESSION_LOCK == wParam)
  {
    AfxMessageBox("test");
  }
 
  return 0;
}

Open in new window

Um, you cannot see the message box in your hanler since 'lock' actually meand switching to a different desktop - try 'MessageBeep()' instead.