When "Lock Computer" is selected, Rendering device not found

I'm having trouble detecting when a computer is sent into locked mode.  

The problem is that if my application is maximized, the 3D module gives the error "Render Error: Cannot get a D3D device for rendering" as soon as the computer enters locked mode.  In most cases the app ends up having to be killed by the task manager.

I need to be able to detect when the computer is locked or when the rendering device is not available so that I can suspend drawing until the user loggs back in.
bigsteve87Asked:
Who is Participating?
 
jkrCommented:
That in fact is quite simple if you use a Winlogon Notification Package, see http://msdn.microsoft.com/library/en-us/secauthn/security/winlogon_notification_packages.asp ("Winlogon Notification Packages"), all you need to do is to create a DLL that contains

// Here is the event handler for the Winlogon Lock event.
VOID WLEventLockComputer (PWLX_NOTIFICATION_INFO pInfo)
{

    // Print the name of the handler to debug output.
    // You can replace this with more useful functionality.
    OutputDebugString (TEXT("NOTIFY:  Entering WLEventLockComputer.\r\n"));
}

// Here is the event handler for the Winlogon Unlock event.
VOID WLEventUnlockComputer (PWLX_NOTIFICATION_INFO pInfo)
{

    // Print the name of the handler to debug output.
    // You can replace this with more useful functionality.
    OutputDebugString (TEXT("NOTIFY:  Entering WLEventLogff.\r\n"));
}

and register these two functions in the Registry under

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify\MyLockUnlockHandler

as described in http://msdn.microsoft.com/library/en-us/secauthn/security/registry_entries.asp ("Registry Entries")

Your handlers can just e.g. set an event so that your app can stop rendering and start it later on again.
0
 
bigsteve87Author Commented:
Thanks jkr

That is exactly what I was looking for, but this bug doesn't really justify the time it will take to create and add a new DLL to the project / installation / patcher.

Since this only happens when the main window is maximized, I found a message sent by windows with Spy++ called WM_WINDOWPOSCHANGING when I lock the computer, the only difference between when the message is sent here and when it is sent normally is that here WINDOWPOS.x and y are set to -4.  That seems to work for now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.