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
;
55 // break out of screen-saver if any keyboard activity
58 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
61 // break out of screen-saver if any mouse activity
69 // If we've got a parent then we must be a preview
70 if(GetParent(hwnd
) != 0)
75 GetCursorPos(&ptLast
);
79 GetCursorPos(&ptCursor
);
81 // if the mouse has moved more than 3 pixels then exit
82 if(abs(ptCursor
.x
- ptLast
.x
) >= 3 || abs(ptCursor
.y
- ptLast
.y
) >= 3)
83 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
90 return MazeWndProc(hwnd
, msg
, wParam
, lParam
);
93 HWND
InitSaver(HWND hwndParent
)
97 ZeroMemory(&wc
, sizeof(wc
));
98 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
99 wc
.lpfnWndProc
= WndProc
;
100 wc
.lpszClassName
= APPNAME
;
101 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
107 GetClientRect(hwndParent
, &rect
);
108 hwnd
= CreateWindow(APPNAME
, APPNAME
,
109 WS_VISIBLE
| WS_CHILD
,
119 hwnd
= CreateWindow(APPNAME
, APPNAME
,
120 WS_VISIBLE
| WS_POPUP
| WS_EX_TOPMOST
,
122 GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
125 ShowWindow(hwnd
, SW_SHOWMAXIMIZED
);
132 void ParseCommandLine(PSTR szCmdLine
, int *chOption
, HWND
*hwndParent
)
134 int ch
= *szCmdLine
++;
136 if(ch
== '-' || ch
== '/')
139 if(ch
>= 'A' && ch
<= 'Z')
148 while(ch
== ' ' || ch
== '\t')
153 unsigned int i
= atoi(szCmdLine
- 1);
154 *hwndParent
= (HWND
)i
;
165 LoadString(hInstance
,
170 LoadString(hInstance
,
178 MB_OK
| MB_ICONWARNING
);
181 int WINAPI
WinMain (HINSTANCE hInst
,
193 ParseCommandLine(lpCmdLine
, &chOption
, &hwndParent
);
195 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, TRUE
, &nPreviousState
, 0);
200 hwndChild
= InitSaver(0);
204 hwndChild
= InitSaver(hwndParent
);
213 MazeMain(hInst
, hPrev
, lpCmdLine
, hwndChild
);
215 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, FALSE
, &nPreviousState
, 0);