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).
You can not find that put in a direct way, but 'WTSRegisterSessionNotific ation()' (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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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;
}
Um, you cannot see the message box in your hanler since 'lock' actually meand switching to a different desktop - try 'MessageBeep()' instead.