DOCUMENT:Q238882 08-AUG-2001 [win95x] TITLE :HOWTO: Know When Your Screen Saver Starts PRODUCT :Microsoft Windows 95.x Retail Product PROD/VER:WINDOWS:95,98; winnt:4.0 OPER/SYS: KEYWORDS:kbHook kbOSWinNT400 kbOSWin2000 kbOSWin95 kbOSWin98 kbDSupport kbhowto ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Windows 98 - Microsoft Windows 95 - Microsoft Windows NT Server version 4.0 - Microsoft Windows NT Workstation version 4.0 - Microsoft Windows 2000 Advanced Server - Microsoft Windows 2000 Server - Microsoft Windows 2000 Professional ------------------------------------------------------------------------------- SUMMARY ======= A screen saver will start, pending your choices, whenever there is no mouse or keyboard activity for the current screen saver timeout period. Some applications need to know when the screen saver has started in order to do some background processing, for example, writing or updating the data to disk. MORE INFORMATION ================ When a screen saver starts, it posts a WM_SYSCOMMAND message to the foreground window with WPARAM as SC_SCREENSAVE. To detect and notify other applications of this event, use the following steps: 1. Install WH_GETMESSAGE Global hook. hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookProc, (HINSTANCE) hMod, 0); 2. Define a user-defined registered message for example, "ScreenSaverStarted". UINT WM_SCRNSVSTART = RegisterWindowMessage("ScreenSaverStarted"); 3. Broadcast this message to all top-level windows in the system. LRESULT CALLBACK HookProc(UINT code , WPARAM wParam, LPARAM lParam) { MSG *msg = (MSG *)lParam; if ( msg->message == WM_SYSCOMMAND && msg->wParam == SC_SCREENSAVE) { // broadcast message to all top-level windows // Or execute some other code here PostMessage(HWND_BROADCAST, WM_SCRNSVSTART, 0, 0); } // Always call next hook in chain return CallNextHookEx(hHook, code, wParam, lParam); } 4. Uninstall the hook. UnhookWindowsHookEx(hHook); On Windows 98 and Windows 2000, you can query the system by calling SystemParametersInfo with uiAction as SPI_GETSCREENSAVERRUNNING. BOOL bActive; SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL,(LPVOID) &bActive, NULL); //bActive will be true if Screen Saver is running REFERENCES ========== For additional information, please click the article number(s) below to view the article(s) in the Microsoft Knowledge Base: Q140723 HOWTO: Force a Screen Saver to Close Once Started in Windows NT Q150785 HOWTO: Detect If a Screen Saver Is Running on Windows NT (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Gagandeep Singh, Microsoft Corporation Additional query words: ====================================================================== Keywords : kbHook kbOSWinNT400 kbOSWin2000 kbOSWin95 kbOSWin98 kbDSupport kbhowto Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT400search kbwin2000AdvServ kbwin2000AdvServSearch kbwin2000Serv kbWinNTSsearch kbWinNTS400search kbWinNTS400 kbwin2000ServSearch kbwin2000Search kbwin2000ProSearch kbwin2000Pro kbWin95search kbWin98search kbWinAdvServSearch kbZNotKeyword3 kbWin98 Version : WINDOWS:95,98; winnt:4.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.