Mega Code Archive

 
Categories / Delphi / Examples
 

Execute screensaver, then force execute your application at the same time

Title: Execute screensaver, then force execute your application at the same time Question: if you want to force execute your application, when screensaver starting Answer: : function KillScreenSaverWndProc(hwndx: HWND; lParamx: LPARAM): boolean; begin PostMessage(hwndx, WM_CLOSE, 0, 0); Result := true; end; : var osversioninfo: TOSVersionInfo; hssWnd: HWND; hDeskWnd: HDESK; begin osversioninfo.dwOSVersionInfoSize := sizeof(osversioninfo); GetVersionEx(osversioninfo); case osversioninfo.dwPlatformId of VER_PLATFORM_WIN32_WINDOWS: begin hssWnd := FindWindow('WindowsScreenSaverClass', nil); if hwwWnd 0 then PostMessage(hsswnd, WM_CLOSE, 0, 0); end; VER_PLATFORM_WIN32_NT: begin hDeskWnd := OpenDesktop( 'Screen-saver', 0, false, DESKTOP_READOBJECTS or DESKTOP_WRITEOBJECTS ); if hDeskWnd 0 then begin EnumDesktopWindows(hDeskWnd, TFNWndEnumProc(@KillScreenSaverWndProc), 0); CloseDesktop(hDeskWnd); end end; end; end;