ReactOS 0.4.15-dev-8145-ga541a46
scrnsave.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winuser.h>
#include <tchar.h>
#include <stdlib.h>
#include <scrnsave.h>
Include dependency graph for scrnsave.c:

Go to the source code of this file.

Macros

#define CLASS_SCRNSAVE   TEXT("WindowsScreenSaverClass")
 
#define ISNUM(c)   ((c) >= '0' && (c) <= '9')
 

Functions

static int ISSPACE (TCHAR c)
 
static ULONG_PTR _toulptr (const TCHAR *s)
 
static LRESULT WINAPI SysScreenSaverProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
LRESULT WINAPI DefScreenSaverProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static BOOL RegisterScreenSaverClass (void)
 
static int LaunchConfig (HWND hParent)
 
static int LaunchScreenSaver (HWND hParent)
 
int APIENTRY _tWinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR CmdLine, int nCmdShow)
 

Variables

HWND hMainWindow = NULL
 
BOOL fChildPreview = FALSE
 
HINSTANCE hMainInstance
 
TCHAR szName [TITLEBARNAMELEN]
 
TCHAR szAppName [APPNAMEBUFFERLEN]
 
TCHAR szIniFile [MAXFILELEN]
 
TCHAR szScreenSaver [22]
 
TCHAR szHelpFile [MAXFILELEN]
 
TCHAR szNoHelpMemory [BUFFLEN]
 
UINT MyHelpMessage
 
static POINT pt_orig
 
static BOOL pt_init = FALSE
 

Macro Definition Documentation

◆ CLASS_SCRNSAVE

#define CLASS_SCRNSAVE   TEXT("WindowsScreenSaverClass")

Definition at line 21 of file scrnsave.c.

◆ ISNUM

#define ISNUM (   c)    ((c) >= '0' && (c) <= '9')

Definition at line 44 of file scrnsave.c.

Function Documentation

◆ _toulptr()

static ULONG_PTR _toulptr ( const TCHAR s)
static

Definition at line 46 of file scrnsave.c.

47{
50 const TCHAR *p;
51
52 for (p = s; *p; p++)
53 if (!ISNUM(*p))
54 break;
55
56 p--;
57 res = 0;
58
59 for (n = 1; p >= s; p--, n *= 10)
60 res += (*p - '0') * n;
61
62 return res;
63}
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLfloat GLfloat p
Definition: glext.h:8902
#define ISNUM(c)
Definition: scrnsave.c:44
uint32_t ULONG_PTR
Definition: typedefs.h:65
char TCHAR
Definition: xmlstorage.h:189

Referenced by _tWinMain().

◆ _tWinMain()

int APIENTRY _tWinMain ( HINSTANCE  hInst,
HINSTANCE  hPrevInst,
LPTSTR  CmdLine,
int  nCmdShow 
)

Definition at line 241 of file scrnsave.c.

242{
243 LPTSTR p;
244
245 UNREFERENCED_PARAMETER(nCmdShow);
246 UNREFERENCED_PARAMETER(hPrevInst);
247
249
250 // Parse the arguments:
251 // -a <hwnd> (Change the password; only for Win9x, unused on WinNT)
252 // -s (Run the screensaver)
253 // -p <hwnd> (Preview)
254 // -c <hwnd> (Configure)
255 for (p = CmdLine; *p; p++)
256 {
257 switch (*p)
258 {
259 case 'S':
260 case 's':
261 // Start the screen saver
262 return LaunchScreenSaver(NULL);
263
264 case 'P':
265 case 'p':
266 {
267 HWND hParent;
268
269 while (ISSPACE(*++p));
270 hParent = (HWND)_toulptr(p);
271
272 // Start the screen saver in preview mode
273 if (hParent && IsWindow(hParent))
274 return LaunchScreenSaver(hParent);
275 else
276 return -1;
277 }
278
279 case 'C':
280 case 'c':
281 {
282 HWND hParent;
283
284 if (p[1] == ':')
285 hParent = (HWND)_toulptr(p + 2);
286 else
287 hParent = GetForegroundWindow();
288
289 // Display the configuration dialog
290 if (hParent && IsWindow(hParent))
291 return LaunchConfig(hParent);
292 else
293 return -1;
294 }
295
296 case '-':
297 case '/':
298 case ' ':
299 default:
300 break;
301 }
302 }
303
304 return LaunchConfig(NULL);
305}
#define NULL
Definition: types.h:112
HANDLE HWND
Definition: compat.h:19
static const WCHAR CmdLine[]
Definition: install.c:48
HINSTANCE hInst
Definition: dxdiag.c:13
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
static int ISSPACE(TCHAR c)
Definition: scrnsave.c:39
static int LaunchConfig(HWND hParent)
Definition: scrnsave.c:166
HINSTANCE hMainInstance
Definition: scrnsave.c:26
static ULONG_PTR _toulptr(const TCHAR *s)
Definition: scrnsave.c:46
static int LaunchScreenSaver(HWND hParent)
Definition: scrnsave.c:177
BOOL WINAPI IsWindow(_In_opt_ HWND)
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ DefScreenSaverProc()

LRESULT WINAPI DefScreenSaverProc ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 92 of file scrnsave.c.

93{
94 // Don't do any special processing when in preview mode
95 if (fChildPreview)
96 return DefWindowProc(hWnd, uMsg, wParam, lParam);
97
98 switch (uMsg)
99 {
100 case WM_NCACTIVATE:
101 case WM_ACTIVATE:
102 case WM_ACTIVATEAPP:
103 if (!wParam)
104 {
105 // wParam is FALSE, so the screen saver is losing the focus.
106 PostMessage(hWnd, WM_CLOSE, 0, 0);
107 }
108 break;
109
110 case WM_MOUSEMOVE:
111 {
112 POINT pt;
114
115 if (!pt_init)
116 {
117 pt_orig = pt;
118 pt_init = TRUE;
119 break;
120 }
121
122 if (abs(pt.x-pt_orig.x) > 10 || abs(pt.y-pt_orig.y) > 10)
123 PostMessage(hWnd, WM_CLOSE, 0, 0);
124 break;
125 }
126
127 case WM_LBUTTONDOWN:
128 case WM_MBUTTONDOWN:
129 case WM_RBUTTONDOWN:
130 case WM_XBUTTONDOWN:
131 case WM_KEYDOWN:
132 case WM_KEYUP:
133 case WM_SYSKEYDOWN:
134 // Send a WM_CLOSE to close the screen saver (allows
135 // the screen saver to perform clean-up tasks)
136 PostMessage(hWnd, WM_CLOSE, 0, 0);
137 break;
138
139 case WM_SETCURSOR:
141 return TRUE;
142 }
143
144 return DefWindowProc(hWnd, uMsg, wParam, lParam);
145}
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define pt(x, y)
Definition: drawing.c:79
#define abs(i)
Definition: fconv.c:206
#define DefWindowProc
Definition: ros2win.h:31
static POINT pt_orig
Definition: scrnsave.c:36
BOOL fChildPreview
Definition: scrnsave.c:25
static BOOL pt_init
Definition: scrnsave.c:37
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
#define WM_CLOSE
Definition: winuser.h:1621
#define WM_KEYUP
Definition: winuser.h:1716
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2701
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define WM_MOUSEMOVE
Definition: winuser.h:1775
#define WM_LBUTTONDOWN
Definition: winuser.h:1776
#define WM_ACTIVATE
Definition: winuser.h:1612
#define WM_RBUTTONDOWN
Definition: winuser.h:1779
#define WM_NCACTIVATE
Definition: winuser.h:1688
#define PostMessage
Definition: winuser.h:5832
#define WM_SETCURSOR
Definition: winuser.h:1636
#define WM_ACTIVATEAPP
Definition: winuser.h:1632
#define WM_KEYDOWN
Definition: winuser.h:1715
#define WM_SYSKEYDOWN
Definition: winuser.h:1719
#define WM_MBUTTONDOWN
Definition: winuser.h:1782

Referenced by ScreenSaverProc().

◆ ISSPACE()

static int ISSPACE ( TCHAR  c)
static

Definition at line 39 of file scrnsave.c.

40{
41 return (c == ' ' || c == '\t');
42}
const GLubyte * c
Definition: glext.h:8905

Referenced by _tWinMain().

◆ LaunchConfig()

static int LaunchConfig ( HWND  hParent)
static

Definition at line 166 of file scrnsave.c.

167{
168 // Only show the dialog if the RegisterDialogClasses function succeeded.
169 // This is the same behaviour as MS' scrnsave.lib.
171 return -1;
172
175}
BOOL CALLBACK ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: 3dtext.c:397
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
Definition: 3dtext.c:432
#define DLGPROC
Definition: maze.c:62
#define DLG_SCRNSAVECONFIGURE
Definition: scrnsave.h:30
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DialogBox
Definition: winuser.h:5761

Referenced by _tWinMain().

◆ LaunchScreenSaver()

static int LaunchScreenSaver ( HWND  hParent)
static

Definition at line 177 of file scrnsave.c.

178{
179 LPCTSTR lpWindowName;
180 UINT style, exstyle;
181 RECT rc;
182 MSG msg;
183
185 {
186 MessageBox(NULL, TEXT("RegisterClass() failed"), NULL, MB_ICONHAND);
187 return -1;
188 }
189
190 // A slightly different approach needs to be used when displaying in a preview window
191 if (hParent)
192 {
194 lpWindowName = TEXT("Preview");
195
197 exstyle = 0;
198
199 GetClientRect(hParent, &rc);
200 rc.left = 0;
201 rc.top = 0;
202 }
203 else
204 {
206 lpWindowName = TEXT("Screen Saver");
207
210
211 // Get the left & top side coordinates of the virtual screen
214 // Get the width and height of the virtual screen
217 }
218
219 // Create the main screen saver window
220 hMainWindow = CreateWindowEx(exstyle, CLASS_SCRNSAVE, lpWindowName, style,
221 rc.left, rc.top, rc.right, rc.bottom,
222 hParent, NULL, hMainInstance, NULL);
223 if (!hMainWindow)
224 return -1;
225
226 // Display window and start pumping messages
228 if (!hParent)
230
231 while (GetMessage(&msg, NULL, 0, 0))
232 {
235 }
236
237 return msg.wParam;
238}
Arabic default style
Definition: afstyles.h:94
#define msg(x)
Definition: auth_time.c:54
#define FALSE
Definition: types.h:117
#define TEXT(s)
Definition: k32.h:26
unsigned int UINT
Definition: ndis.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_POPUP
Definition: pedump.c:616
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_EX_TOPMOST
Definition: pedump.c:647
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define CLASS_SCRNSAVE
Definition: scrnsave.c:21
HWND hMainWindow
Definition: scrnsave.c:24
static BOOL RegisterScreenSaverClass(void)
Definition: scrnsave.c:148
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define CreateWindowEx
Definition: winuser.h:5755
#define SM_CYVIRTUALSCREEN
Definition: winuser.h:1039
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define MB_ICONHAND
Definition: winuser.h:788
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
#define SM_CXVIRTUALSCREEN
Definition: winuser.h:1038
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define MessageBox
Definition: winuser.h:5822
#define SW_SHOW
Definition: winuser.h:775
#define DispatchMessage
Definition: winuser.h:5765
#define SM_XVIRTUALSCREEN
Definition: winuser.h:1036
int WINAPI GetSystemMetrics(_In_ int)
#define SM_YVIRTUALSCREEN
Definition: winuser.h:1037
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

Referenced by _tWinMain().

◆ RegisterScreenSaverClass()

static BOOL RegisterScreenSaverClass ( void  )
static

Definition at line 148 of file scrnsave.c.

149{
150 WNDCLASS cls;
151
152 cls.hCursor = NULL;
154 cls.lpszMenuName = NULL;
160 cls.cbWndExtra = 0;
161 cls.cbClsExtra = 0;
162
163 return (RegisterClass(&cls) != 0);
164}
#define ID_APP
Definition: scrnsave.h:33
static LRESULT WINAPI SysScreenSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:66
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
#define MAKEINTATOM(i)
Definition: winbase.h:1463
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BLACK_BRUSH
Definition: wingdi.h:896
#define CS_VREDRAW
Definition: winuser.h:658
#define CS_HREDRAW
Definition: winuser.h:653
#define CS_DBLCLKS
Definition: winuser.h:651
#define LoadIcon
Definition: winuser.h:5813
#define CS_SAVEBITS
Definition: winuser.h:657
#define RegisterClass
Definition: winuser.h:5836
#define CS_PARENTDC
Definition: winuser.h:656

Referenced by LaunchScreenSaver().

◆ SysScreenSaverProc()

static LRESULT WINAPI SysScreenSaverProc ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 66 of file scrnsave.c.

67{
68 switch(uMsg)
69 {
70 case WM_DESTROY:
72 break;
73
74 case WM_SYSCOMMAND:
75 if (!fChildPreview)
76 {
77 switch (wParam)
78 {
79 case SC_CLOSE: // - Closing the screen saver, or...
80 case SC_NEXTWINDOW: // - Switching to
81 case SC_PREVWINDOW: // different windows, or...
82 case SC_SCREENSAVE: // - Starting another screen saver:
83 return FALSE; // Fail it!
84 }
85 }
86 break;
87 }
88
89 return ScreenSaverProc(hWnd, uMsg, wParam, lParam);
90}
LRESULT CALLBACK ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: 3dtext.c:259
#define SC_SCREENSAVE
Definition: mmsystem.h:933
#define WM_SYSCOMMAND
Definition: winuser.h:1741
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SC_PREVWINDOW
Definition: winuser.h:2591
#define SC_NEXTWINDOW
Definition: winuser.h:2590
#define SC_CLOSE
Definition: winuser.h:2592
#define WM_DESTROY
Definition: winuser.h:1609

Referenced by RegisterScreenSaverClass().

Variable Documentation

◆ fChildPreview

BOOL fChildPreview = FALSE

Definition at line 25 of file scrnsave.c.

Referenced by DefScreenSaverProc(), LaunchScreenSaver(), and SysScreenSaverProc().

◆ hMainInstance

◆ hMainWindow

HWND hMainWindow = NULL

Definition at line 24 of file scrnsave.c.

Referenced by LaunchScreenSaver().

◆ MyHelpMessage

UINT MyHelpMessage

Definition at line 33 of file scrnsave.c.

◆ pt_init

BOOL pt_init = FALSE
static

Definition at line 37 of file scrnsave.c.

Referenced by DefScreenSaverProc().

◆ pt_orig

POINT pt_orig
static

Definition at line 36 of file scrnsave.c.

Referenced by DefScreenSaverProc().

◆ szAppName

TCHAR szAppName[APPNAMEBUFFERLEN]

Definition at line 28 of file scrnsave.c.

◆ szHelpFile

TCHAR szHelpFile[MAXFILELEN]

◆ szIniFile

◆ szName

Definition at line 27 of file scrnsave.c.

◆ szNoHelpMemory

TCHAR szNoHelpMemory[BUFFLEN]

Definition at line 32 of file scrnsave.c.

◆ szScreenSaver

TCHAR szScreenSaver[22]

Definition at line 30 of file scrnsave.c.