Sync with trunk (r48144)
[reactos.git] / base / applications / screensavers / logon / logon.c
1 /*
2 * Copyright 2003 J Brown
3 * Copyright 2006 Eric Kohl
4 * Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <windows.h>
22 #include <scrnsave.h>
23 #include <tchar.h>
24 #include "resource.h"
25
26 #define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
27
28 #define APPNAME _T("Logon")
29 #define APP_TIMER 1
30 #define APP_TIMER_INTERVAL 2000
31
32 HBITMAP GetScreenSaverBitmap (void)
33 {
34 OSVERSIONINFOEX osvi;
35
36 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
37 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
38 GetVersionEx ((OSVERSIONINFO *) &osvi);
39
40 switch(osvi.wProductType)
41 {
42 case VER_NT_WORKSTATION:
43 return LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_WORKSTATION), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
44 break;
45 default:
46 return LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SERVER), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
47 break;
48 }
49 }
50
51 LRESULT CALLBACK
52 ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
53 {
54 static RECT rect;
55 static HBITMAP bitmap;
56
57 switch (message)
58 {
59 case WM_CREATE:
60 {
61 bitmap = GetScreenSaverBitmap ();
62
63 if(bitmap == NULL)
64 {
65 MessageBox(
66 hWnd,
67 _T("Fatal Error: Could not load bitmap"),
68 _T("Error"),
69 MB_OK | MB_ICONEXCLAMATION);
70 }
71
72 SetTimer (
73 hWnd,
74 APP_TIMER,
75 APP_TIMER_INTERVAL,
76 NULL);
77
78 break;
79 }
80 case WM_PAINT:
81 {
82 BITMAP bm; /* Bitmap structure as seen in bmWidth & bmHeight */
83 PAINTSTRUCT ps;
84 HDC hdc;
85 HDC hdcMem;
86 HBITMAP hbmOld;
87
88 // Obtain window coordinates.
89 GetClientRect (hWnd, &rect);
90
91 hdc = BeginPaint(hWnd, &ps);
92 hdcMem = CreateCompatibleDC(hdc);
93 hbmOld = SelectObject(hdcMem, bitmap);
94
95 GetObject(bitmap, sizeof(bm), &bm);
96
97 if (rect.right < bm.bmWidth ||
98 rect.bottom < bm.bmHeight)
99 {
100 StretchBlt(
101 hdc,
102 RANDOM (0, rect.right - (bm.bmWidth /5)),
103 RANDOM (0, rect.bottom - (bm.bmHeight /5)),
104 bm.bmWidth /5,
105 bm.bmHeight /5,
106 hdcMem,
107 0,
108 0,
109 bm.bmWidth,
110 bm.bmHeight,
111 SRCCOPY);
112 }
113 else
114 {
115 BitBlt(
116 hdc,
117 RANDOM (0, rect.right - bm.bmWidth),
118 RANDOM (0, rect.bottom - bm.bmHeight),
119 bm.bmWidth,
120 bm.bmHeight,
121 hdcMem,
122 0,
123 0,
124 SRCCOPY);
125 }
126
127 SelectObject(hdcMem, hbmOld);
128 DeleteDC(hdcMem);
129
130 EndPaint(hWnd, &ps);
131 break;
132 }
133 case WM_TIMER:
134 {
135 InvalidateRect(hWnd, NULL, 1);
136 break;
137 }
138 case WM_DESTROY:
139 {
140 KillTimer (hWnd, APP_TIMER);
141 DeleteObject(bitmap);
142 PostQuitMessage(0);
143 break;
144 }
145
146 default:
147 // Pass Windows Messages to the default screensaver window procedure
148 return DefScreenSaverProc(hWnd, message, wParam, lParam);
149 }
150
151 return 0;
152 }
153
154 BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
155 {
156 return FALSE;
157 }
158
159 // This function is only called one time before opening the configuration dialog.
160 // Use it to show a message that no configuration is necesssary and return FALSE to indicate that no configuration dialog shall be opened.
161 BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
162 {
163 TCHAR szMessage[256];
164 TCHAR szTitle[25];
165
166 LoadString(hInst, IDS_TEXT, szMessage, sizeof(szMessage) / sizeof(TCHAR));
167 LoadString(hInst, IDS_DESCRIPTION, szTitle, sizeof(szTitle) / sizeof(TCHAR));
168
169 MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONEXCLAMATION);
170
171 return FALSE;
172 }