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")
26 LRESULT CALLBACK
MazeWndProc(
27 HWND hWnd
, // window handle
28 UINT message
, // type of message
29 WPARAM wParam
, // additional information
30 LPARAM lParam
); // additional information
32 int APIENTRY
MazeMain(
34 HINSTANCE hPrevInstance
,
40 BOOL fullscreen
= FALSE
;
43 LRESULT WINAPI
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
46 static POINT ptCursor
;
47 static BOOL fFirstTime
= TRUE
;
57 // break out of screen-saver if any keyboard activity
60 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
63 // break out of screen-saver if any mouse activity
71 // If we've got a parent then we must be a preview
72 if(GetParent(hwnd
) != 0)
77 GetCursorPos(&ptLast
);
81 GetCursorPos(&ptCursor
);
83 // if the mouse has moved more than 3 pixels then exit
84 if(abs(ptCursor
.x
- ptLast
.x
) >= 3 || abs(ptCursor
.y
- ptLast
.y
) >= 3)
85 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
92 return MazeWndProc(hwnd
, msg
, wParam
, lParam
);
95 HWND
InitSaver(HWND hwndParent
)
99 ZeroMemory(&wc
, sizeof(wc
));
100 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
101 wc
.lpfnWndProc
= WndProc
;
102 wc
.lpszClassName
= APPNAME
;
103 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
109 GetClientRect(hwndParent
, &rect
);
110 hwnd
= CreateWindow(APPNAME
, APPNAME
,
111 WS_VISIBLE
| WS_CHILD
,
121 hwnd
= CreateWindowEx(WS_EX_TOPMOST
,
124 WS_VISIBLE
| WS_POPUP
,
127 GetSystemMetrics(SM_CXSCREEN
),
128 GetSystemMetrics(SM_CYSCREEN
),
140 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
| SWP_SHOWWINDOW
);
148 void ParseCommandLine(PSTR szCmdLine
, int *chOption
, HWND
*hwndParent
)
150 int ch
= *szCmdLine
++;
152 if(ch
== '-' || ch
== '/')
155 if(ch
>= 'A' && ch
<= 'Z')
164 while(ch
== ' ' || ch
== '\t')
169 unsigned int i
= atoi(szCmdLine
- 1);
170 *hwndParent
= (HWND
)i
;
181 LoadString(hInstance
,
186 LoadString(hInstance
,
194 MB_OK
| MB_ICONWARNING
);
197 int WINAPI
WinMain (HINSTANCE hInst
,
209 ParseCommandLine(lpCmdLine
, &chOption
, &hwndParent
);
211 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, TRUE
, &nPreviousState
, 0);
216 hwndChild
= InitSaver(0);
220 hwndChild
= InitSaver(hwndParent
);
229 MazeMain(hInst
, hPrev
, lpCmdLine
, hwndChild
);
231 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, FALSE
, &nPreviousState
, 0);