Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How to force a screen saver to close once started in Windows NT, Windows 2000, and Windows Server 2003
Article ID: 140723 - View products that this article applies to.
This article was previously published under Q140723
Sometimes applications need to terminate a screen saver that is already running. In Microsoft Windows 95, a screen saver could be terminated easily by posting a WM_CLOSE message to the currently active screen saver window as in this example:Microsoft Windows NT, however, introduces the concept of separate desktops, so that applications can run on one, and screen savers can run on another. This makes screen saver termination under Windows NT, Windows 2000, and Windows Server 2003 a bit more difficult.
The process of obtaining a handle to the currently active screen saver window is different for operating systems that are later than Microsoft Windows 95. On Microsoft Windows NT, on Microsoft Windows 2000, and on Microsoft Windows Server 2003, the screen saver may run on either the default desktop or on a separate desktop, depending on a setting in the display properties:
To do this, get a handle to the screen saver's desktop, enumerate that desktop's windows, and then post a WM_CLOSE to the screen saver window.
The following code demonstrates how to do this. Note that if a screen saver password is set, the following code brings up the password dialog box, prompts the user for a password, and then actually terminates the screen saver application.
Note that terminating a screen saver that is already running as demonstrated above is totally separate from disabling the screen saver altogether, so that no screen saver starts after the designated time period expires. This can be done easily using:
This method works well for terminating the currently running screen saver. However, one problem that you might encounter is that the system will not restart the screen saver unless the user moves the mouse or presses a key. If you need the screen saver to start up again, you'll need to reinitialize the time-out period. Do this by using one of the following methods:
Article ID: 140723 - Last Review: February 22, 2007 - Revision: 3.2