2 * Copyright 2003 J Brown
3 * Copyright 2006 Eric Kohl
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #define APPNAME _T("Scrnsave")
29 BOOL fullscreen
= FALSE
;
32 LRESULT WINAPI
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
35 static POINT ptCursor
;
36 static BOOL fFirstTime
= TRUE
;
45 // break out of screen-saver if any keyboard activity
48 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
51 // break out of screen-saver if any mouse activity
59 // If we've got a parent then we must be a preview
60 if(GetParent(hwnd
) != 0)
65 GetCursorPos(&ptLast
);
69 GetCursorPos(&ptCursor
);
71 // if the mouse has moved more than 3 pixels then exit
72 if(abs(ptCursor
.x
- ptLast
.x
) >= 3 || abs(ptCursor
.y
- ptLast
.y
) >= 3)
73 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
80 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
83 void InitSaver(HWND hwndParent
)
86 ZeroMemory(&wc
, sizeof(wc
));
87 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
88 wc
.lpfnWndProc
= WndProc
;
89 wc
.lpszClassName
= APPNAME
;
90 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
96 GetClientRect(hwndParent
, &rect
);
97 CreateWindow(APPNAME
, APPNAME
,
98 WS_VISIBLE
| WS_CHILD
,
109 hwnd
= CreateWindowEx(WS_EX_TOPMOST
,
112 WS_VISIBLE
| WS_POPUP
,
114 GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
120 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
127 VOID
ParseCommandLine(LPWSTR szCmdLine
, UCHAR
*chOption
, HWND
*hwndParent
)
129 UCHAR ch
= *szCmdLine
++;
131 if(ch
== '-' || ch
== '/')
134 if(ch
>= 'A' && ch
<= 'Z')
135 ch
+= 'a' - 'A'; //convert to lower case
143 while(ch
== ' ' || ch
== '\t')
148 unsigned int i
= _wtoi(szCmdLine
- 1);
149 *hwndParent
= (HWND
)i
;
160 LoadString(hInstance
,
165 LoadString(hInstance
,
173 MB_OK
| MB_ICONWARNING
);
177 int CALLBACK
wWinMain (HINSTANCE hInst
,
189 ParseCommandLine(lpCmdLine
, &chOption
, &hwndParent
);
191 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, TRUE
, &nPreviousState
, 0);
200 InitSaver(hwndParent
);
209 while (GetMessage(&Message
, 0, 0, 0))
210 DispatchMessage(&Message
);
212 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, FALSE
, &nPreviousState
, 0);
214 return Message
.wParam
;