- Fix logon screensaver preview
[reactos.git] / reactos / 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
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
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
85 // Obtain window coordinates.
86 GetClientRect (hWnd, &rect);
87
88 HDC hdc = BeginPaint(hWnd, &ps);
89 HDC hdcMem = CreateCompatibleDC(hdc);
90 HBITMAP hbmOld = SelectObject(hdcMem, bitmap);
91
92 GetObject(bitmap, sizeof(bm), &bm);
93
94 if (rect.right < bm.bmWidth ||
95 rect.bottom < bm.bmHeight)
96 {
97 StretchBlt(
98 hdc,
99 RANDOM (0, rect.right - (bm.bmWidth /5)),
100 RANDOM (0, rect.bottom - (bm.bmHeight /5)),
101 bm.bmWidth /5,
102 bm.bmHeight /5,
103 hdcMem,
104 0,
105 0,
106 bm.bmWidth,
107 bm.bmHeight,
108 SRCCOPY);
109 }
110 else
111 {
112 BitBlt(
113 hdc,
114 RANDOM (0, rect.right - bm.bmWidth),
115 RANDOM (0, rect.bottom - bm.bmHeight),
116 bm.bmWidth,
117 bm.bmHeight,
118 hdcMem,
119 0,
120 0,
121 SRCCOPY);
122 }
123
124 SelectObject(hdcMem, hbmOld);
125 DeleteDC(hdcMem);
126
127 EndPaint(hWnd, &ps);
128 break;
129 }
130 case WM_TIMER:
131 {
132 InvalidateRect(hWnd, NULL, 1);
133 break;
134 }
135 case WM_DESTROY:
136 {
137 KillTimer (hWnd, APP_TIMER);
138 DeleteObject(bitmap);
139 PostQuitMessage(0);
140 break;
141 }
142
143 default:
144 // Pass Windows Messages to the default screensaver window procedure
145 return DefScreenSaverProc(hWnd, message, wParam, lParam);
146 }
147
148 return 0;
149 }
150
151 BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
152 {
153 return FALSE;
154 }
155
156 // This function is only called one time before opening the configuration dialog.
157 // Use it to show a message that no configuration is necesssary and return FALSE to indicate that no configuration dialog shall be opened.
158 BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
159 {
160 TCHAR szMessage[256];
161 TCHAR szTitle[25];
162
163 LoadString(hInst, IDS_TEXT, szMessage, sizeof(szMessage) / sizeof(TCHAR));
164 LoadString(hInst, IDS_DESCRIPTION, szTitle, sizeof(szTitle) / sizeof(TCHAR));
165
166 MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONEXCLAMATION);
167
168 return FALSE;
169 }