5a8b9f3349c9b769d1d60dc12e68160b151514fb
[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 #define BITMAP_HEIGHT 240
33 #define BITMAP_WIDTH 340
34
35 HBITMAP GetScreenSaverBitmap (void)
36 {
37 OSVERSIONINFOEX osvi;
38
39 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
40 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
41 GetVersionEx ((OSVERSIONINFO *) &osvi);
42
43 switch(osvi.wProductType)
44 {
45 case VER_NT_WORKSTATION:
46 return LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_WORKSTATION), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
47 break;
48 default:
49 return LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SERVER), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
50 break;
51 }
52 }
53
54 LRESULT CALLBACK
55 ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
56 {
57 static RECT rect;
58 static HBITMAP bitmap;
59
60 switch (message)
61 {
62 case WM_CREATE:
63 {
64 GetClientRect(hWnd, &rect);
65
66 bitmap = GetScreenSaverBitmap ();
67
68 if(bitmap == NULL)
69 {
70 MessageBox(
71 hWnd,
72 _T("Fatal Error: Could not load bitmap"),
73 _T("Error"),
74 MB_OK | MB_ICONEXCLAMATION);
75 }
76
77 SetTimer (
78 hWnd,
79 APP_TIMER,
80 APP_TIMER_INTERVAL,
81 NULL);
82
83 break;
84 }
85 case WM_PAINT:
86 {
87 BITMAP bm; /* Bitmap structure as seen in bmWidth & bmHeight */
88 PAINTSTRUCT ps;
89
90 HDC hdc = BeginPaint(hWnd, &ps);
91 HDC hdcMem = CreateCompatibleDC(hdc);
92 HBITMAP hbmOld = SelectObject(hdcMem, bitmap);
93
94 GetObject(bitmap, sizeof(bm), &bm);
95
96 bm.bmWidth = 1000;
97 bm.bmHeight = 700;
98
99 BitBlt(
100 hdc,
101 RANDOM (0, rect.right - BITMAP_WIDTH),
102 RANDOM (0, rect.bottom - BITMAP_HEIGHT),
103 bm.bmWidth,
104 bm.bmHeight,
105 hdcMem,
106 5,
107 5,
108 SRCCOPY);
109
110 SelectObject(hdcMem, hbmOld);
111 DeleteDC(hdcMem);
112
113 EndPaint(hWnd, &ps);
114 break;
115 }
116 case WM_TIMER:
117 {
118 InvalidateRect(hWnd, NULL, 1);
119 break;
120 }
121 case WM_DESTROY:
122 {
123 KillTimer (hWnd, APP_TIMER);
124 DeleteObject(bitmap);
125 PostQuitMessage(0);
126 break;
127 }
128
129 default:
130 // Pass Windows Messages to the default screensaver window procedure
131 return DefScreenSaverProc(hWnd, message, wParam, lParam);
132 }
133
134 return 0;
135 }
136
137 BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
138 {
139 return FALSE;
140 }
141
142 // This function is only called one time before opening the configuration dialog.
143 // Use it to show a message that no configuration is necesssary and return FALSE to indicate that no configuration dialog shall be opened.
144 BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
145 {
146 TCHAR szMessage[256];
147 TCHAR szTitle[25];
148
149 LoadString(hInst, IDS_TEXT, szMessage, sizeof(szMessage) / sizeof(TCHAR));
150 LoadString(hInst, IDS_DESCRIPTION, szTitle, sizeof(szTitle) / sizeof(TCHAR));
151
152 MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONEXCLAMATION);
153
154 return FALSE;
155 }