2 * Copyright 2003 J Brown
3 * Copyright 2006 Eric Kohl
4 * Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 #define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
27 #define APPNAME _T("Logon")
29 #define APP_TIMER_INTERVAL 2000
31 #define BITMAP_HEIGHT 240;
32 #define BITMAP_WIDTH 340
36 BOOL fullscreen
= FALSE
;
38 void DrawScreen (HDC hdc
, HDC hMemDC
, RECT rect
)
42 int width
= BITMAP_WIDTH
;
43 int height
= BITMAP_HEIGHT
;
51 x
= RANDOM (0, rect
.right
- width
);
52 y
= RANDOM (0, rect
.bottom
- height
);
66 HBITMAP
GetScreenSaverBitmap (void)
70 ZeroMemory(&osvi
, sizeof(OSVERSIONINFOEX
));
71 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
72 GetVersionEx ((OSVERSIONINFO
*) &osvi
);
74 switch(osvi
.wProductType
)
76 case VER_NT_WORKSTATION
:
77 return LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_WORKSTATION
));
80 return LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_SERVER
));
85 LRESULT WINAPI
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
88 static POINT ptCursor
;
89 static BOOL fFirstTime
= TRUE
;
91 static PAINTSTRUCT ps
;
95 static HBRUSH hBlkBrush
;
96 static HBITMAP bitmap
;
103 hBlkBrush
= (HBRUSH
) GetStockObject(BLACK_BRUSH
);
104 hMemDC
= CreateCompatibleDC(hDC
);
105 GetClientRect(hwnd
, &rect
);
107 bitmap
= GetScreenSaverBitmap ();
113 _T("Fatal Error: Could not load bitmap"),
115 MB_OK
| MB_ICONEXCLAMATION
);
128 hDC
= BeginPaint(hwnd
, &ps
);
129 SelectObject(hMemDC
, bitmap
);
130 DrawScreen (hDC
, hMemDC
, rect
);
136 if (wParam
== APP_TIMER
)
138 InvalidateRect(hwnd
, NULL
, 1);
143 SelectObject(hDC
, hBlkBrush
);
156 KillTimer (hwnd
, APP_TIMER
);
157 DeleteObject(bitmap
);
163 // break out of screen-saver if any keyboard activity
166 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
169 // break out of screen-saver if any mouse activity
177 // If we've got a parent then we must be a preview
178 if(GetParent(hwnd
) != 0)
183 GetCursorPos(&ptLast
);
187 GetCursorPos(&ptCursor
);
189 // if the mouse has moved more than 3 pixels then exit
190 if(abs(ptCursor
.x
- ptLast
.x
) >= 3 || abs(ptCursor
.y
- ptLast
.y
) >= 3)
191 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
198 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
201 void InitSaver(HWND hwndParent
)
204 ZeroMemory(&wc
, sizeof(wc
));
205 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
206 wc
.lpfnWndProc
= WndProc
;
207 wc
.lpszClassName
= APPNAME
;
208 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
214 GetClientRect(hwndParent
, &rect
);
215 CreateWindow(APPNAME
, APPNAME
,
216 WS_VISIBLE
| WS_CHILD
,
227 hwnd
= CreateWindowEx(WS_EX_TOPMOST
,
230 WS_VISIBLE
| WS_POPUP
,
232 GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
238 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
245 VOID
ParseCommandLine(LPWSTR szCmdLine
, UCHAR
*chOption
, HWND
*hwndParent
)
247 UCHAR ch
= *szCmdLine
++;
249 if(ch
== '-' || ch
== '/')
252 if(ch
>= 'A' && ch
<= 'Z')
253 ch
+= 'a' - 'A'; //convert to lower case
261 while(ch
== ' ' || ch
== '\t')
266 unsigned int i
= _wtoi(szCmdLine
- 1);
267 *hwndParent
= (HWND
)i
;
278 LoadString(hInstance
,
283 LoadString(hInstance
,
291 MB_OK
| MB_ICONWARNING
);
294 int CALLBACK
wWinMain (HINSTANCE hInst
,
306 ParseCommandLine(lpCmdLine
, &chOption
, &hwndParent
);
308 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, TRUE
, &nPreviousState
, 0);
317 InitSaver(hwndParent
);
326 while (GetMessage(&Message
, 0, 0, 0))
327 DispatchMessage(&Message
);
329 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING
, FALSE
, &nPreviousState
, 0);
331 return Message
.wParam
;