ReactOS  0.4.14-dev-342-gdc047f9
scrnsave.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winuser.h>
#include <tchar.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
 

Macro Definition Documentation

◆ CLASS_SCRNSAVE

#define CLASS_SCRNSAVE   TEXT("WindowsScreenSaverClass")

Definition at line 20 of file scrnsave.c.

◆ ISNUM

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

Definition at line 42 of file scrnsave.c.

Function Documentation

◆ _toulptr()

static ULONG_PTR _toulptr ( const TCHAR s)
static

Definition at line 44 of file scrnsave.c.

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

Referenced by _tWinMain().

◆ _tWinMain()

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

Definition at line 239 of file scrnsave.c.

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

◆ DefScreenSaverProc()

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

Definition at line 95 of file scrnsave.c.

96 {
97  // Don't do any special processing when in preview mode
98  if (fChildPreview)
99  return DefWindowProc(hWnd, uMsg, wParam, lParam);
100 
101  switch (uMsg)
102  {
103  case WM_NCACTIVATE:
104  case WM_ACTIVATE:
105  case WM_ACTIVATEAPP:
106  if (!wParam)
107  {
108  // wParam is FALSE, so the screen saver is losing the focus.
109  PostMessage(hWnd, WM_CLOSE, 0, 0);
110  }
111  break;
112 
113  case WM_MOUSEMOVE:
114  {
115  POINT pt;
116  GetCursorPos(&pt);
117  // TODO: Implement mouse move threshold. See:
118  // http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/screensavers/starfield/screensaver.c?r1=67455&r2=67454&pathrev=67455
119  if (pt.x == pt_orig.x && pt.y == pt_orig.y)
120  break;
121 
122  // Fall through
123  }
124 
125  case WM_LBUTTONDOWN:
126  case WM_MBUTTONDOWN:
127  case WM_RBUTTONDOWN:
128  case WM_XBUTTONDOWN:
129  case WM_KEYDOWN:
130  case WM_KEYUP:
131  case WM_SYSKEYDOWN:
132  // Send a WM_CLOSE to close the screen saver (allows
133  // the screen saver to perform clean-up tasks)
134  PostMessage(hWnd, WM_CLOSE, 0, 0);
135  break;
136 
137  case WM_SETCURSOR:
138  SetCursor(NULL);
139  return TRUE;
140  }
141 
142  return DefWindowProc(hWnd, uMsg, wParam, lParam);
143 }
#define TRUE
Definition: types.h:120
long y
Definition: polytest.cpp:48
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
long x
Definition: polytest.cpp:48
#define pt(x, y)
Definition: drawing.c:79
HWND hWnd
Definition: settings.c:17
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
WPARAM wParam
Definition: combotst.c:138
BOOL fChildPreview
Definition: scrnsave.c:24
#define WM_NCACTIVATE
Definition: winuser.h:1670
#define WM_SETCURSOR
Definition: winuser.h:1618
static POINT pt_orig
Definition: scrnsave.c:35
smooth NULL
Definition: ftsmooth.c:416
#define WM_KEYDOWN
Definition: winuser.h:1697
#define DefWindowProc
Definition: ros2win.h:31
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
#define PostMessage
Definition: winuser.h:5733
#define WM_CLOSE
Definition: winuser.h:1603
#define WM_KEYUP
Definition: winuser.h:1698
#define WM_ACTIVATEAPP
Definition: winuser.h:1614
#define WM_ACTIVATE
Definition: winuser.h:1594
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define WM_MBUTTONDOWN
Definition: winuser.h:1764
#define WM_MOUSEMOVE
Definition: winuser.h:1757
#define WM_SYSKEYDOWN
Definition: winuser.h:1701
LPARAM lParam
Definition: combotst.c:139

Referenced by ScreenSaverProc().

◆ ISSPACE()

static int ISSPACE ( TCHAR  c)
static

Definition at line 37 of file scrnsave.c.

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

Referenced by _tWinMain().

◆ LaunchConfig()

static int LaunchConfig ( HWND  hParent)
static

Definition at line 164 of file scrnsave.c.

165 {
166  // Only show the dialog if the RegisterDialogClasses function succeeded.
167  // This is the same behaviour as MS' scrnsave.lib.
169  return -1;
170 
173 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
HINSTANCE hMainInstance
Definition: scrnsave.c:25
#define DialogBox
Definition: winuser.h:5662
BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:29
#define DLG_SCRNSAVECONFIGURE
Definition: scrnsave.h:30
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2870
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
Definition: scrnsave.c:36

Referenced by _tWinMain().

◆ LaunchScreenSaver()

static int LaunchScreenSaver ( HWND  hParent)
static

Definition at line 175 of file scrnsave.c.

176 {
177  LPCTSTR lpWindowName;
178  UINT style, exstyle;
179  RECT rc;
180  MSG msg;
181 
183  {
184  MessageBox(NULL, TEXT("RegisterClass() failed"), NULL, MB_ICONHAND);
185  return -1;
186  }
187 
188  // A slightly different approach needs to be used when displaying in a preview window
189  if (hParent)
190  {
192  lpWindowName = TEXT("Preview");
193 
195  exstyle = 0;
196 
197  GetClientRect(hParent, &rc);
198  rc.left = 0;
199  rc.top = 0;
200  }
201  else
202  {
204  lpWindowName = TEXT("Screen Saver");
205 
207  exstyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
208 
209  // Get the left & top side coordinates of the virtual screen
212  // Get the width and height of the virtual screen
215  }
216 
217  // Create the main screen saver window
218  hMainWindow = CreateWindowEx(exstyle, CLASS_SCRNSAVE, lpWindowName, style,
219  rc.left, rc.top, rc.right, rc.bottom,
221  if (!hMainWindow)
222  return -1;
223 
224  // Display window and start pumping messages
226  if (!hParent)
227  SetCursor(NULL);
228 
229  while (GetMessage(&msg, NULL, 0, 0))
230  {
233  }
234 
235  return msg.wParam;
236 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define MB_ICONHAND
Definition: winuser.h:782
#define DispatchMessage
Definition: winuser.h:5666
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define SM_XVIRTUALSCREEN
Definition: winuser.h:1026
#define SM_CXVIRTUALSCREEN
Definition: winuser.h:1028
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
HWND hMainWindow
Definition: scrnsave.c:23
HINSTANCE hMainInstance
Definition: scrnsave.c:25
LONG top
Definition: windef.h:292
#define WS_CHILD
Definition: pedump.c:617
LONG left
Definition: windef.h:291
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WS_CLIPCHILDREN
Definition: pedump.c:619
LONG right
Definition: windef.h:293
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
BOOL fChildPreview
Definition: scrnsave.c:24
#define CreateWindowEx
Definition: winuser.h:5656
smooth NULL
Definition: ftsmooth.c:416
#define SW_SHOW
Definition: winuser.h:769
#define SM_CYVIRTUALSCREEN
Definition: winuser.h:1029
int WINAPI GetSystemMetrics(_In_ int)
#define CLASS_SCRNSAVE
Definition: scrnsave.c:20
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define WS_EX_TOPMOST
Definition: pedump.c:647
#define MessageBox
Definition: winuser.h:5723
#define SM_YVIRTUALSCREEN
Definition: winuser.h:1027
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define TEXT(s)
Definition: k32.h:26
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define WS_POPUP
Definition: pedump.c:616
unsigned int UINT
Definition: ndis.h:50
#define GetMessage
Definition: winuser.h:5691
static BOOL RegisterScreenSaverClass(void)
Definition: scrnsave.c:146
#define msg(x)
Definition: auth_time.c:54
LONG bottom
Definition: windef.h:294
Arabic default style
Definition: afstyles.h:93
#define WS_VISIBLE
Definition: pedump.c:620

Referenced by _tWinMain().

◆ RegisterScreenSaverClass()

static BOOL RegisterScreenSaverClass ( void  )
static

Definition at line 146 of file scrnsave.c.

147 {
148  WNDCLASS cls;
149 
150  cls.hCursor = NULL;
152  cls.lpszMenuName = NULL;
155  cls.hInstance = hMainInstance;
158  cls.cbWndExtra = 0;
159  cls.cbClsExtra = 0;
160 
161  return (RegisterClass(&cls) != 0);
162 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
HINSTANCE hMainInstance
Definition: scrnsave.c:25
int cbClsExtra
Definition: winuser.h:3139
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3145
static LRESULT WINAPI SysScreenSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:64
HBRUSH hbrBackground
Definition: winuser.h:3144
#define ID_APP
Definition: scrnsave.h:33
int cbWndExtra
Definition: winuser.h:3140
HCURSOR hCursor
Definition: winuser.h:3143
smooth NULL
Definition: ftsmooth.c:416
#define BLACK_BRUSH
Definition: wingdi.h:895
#define CS_VREDRAW
Definition: winuser.h:653
#define CS_SAVEBITS
Definition: winuser.h:652
#define CLASS_SCRNSAVE
Definition: scrnsave.c:20
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3146
UINT style
Definition: winuser.h:3137
HINSTANCE hInstance
Definition: winuser.h:3141
WNDPROC lpfnWndProc
Definition: winuser.h:3138
#define RegisterClass
Definition: winuser.h:5737
#define LoadIcon
Definition: winuser.h:5714
#define CS_PARENTDC
Definition: winuser.h:651
#define MAKEINTATOM(i)
Definition: winbase.h:1423
HICON hIcon
Definition: winuser.h:3142

Referenced by LaunchScreenSaver().

◆ SysScreenSaverProc()

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

Definition at line 64 of file scrnsave.c.

65 {
66  switch(uMsg)
67  {
68  case WM_CREATE:
69  // Mouse is not supposed to move from this position
71  break;
72 
73  case WM_DESTROY:
74  PostQuitMessage(0);
75  break;
76 
77  case WM_SYSCOMMAND:
78  if (!fChildPreview)
79  {
80  switch (wParam)
81  {
82  case SC_CLOSE: // - Closing the screen saver, or...
83  case SC_NEXTWINDOW: // - Switching to
84  case SC_PREVWINDOW: // different windows, or...
85  case SC_SCREENSAVE: // - Starting another screen saver:
86  return FALSE; // Fail it!
87  }
88  }
89  break;
90  }
91 
92  return ScreenSaverProc(hWnd, uMsg, wParam, lParam);
93 }
#define SC_SCREENSAVE
Definition: mmsystem.h:933
HWND hWnd
Definition: settings.c:17
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
WPARAM wParam
Definition: combotst.c:138
BOOL fChildPreview
Definition: scrnsave.c:24
static POINT pt_orig
Definition: scrnsave.c:35
#define WM_DESTROY
Definition: winuser.h:1591
#define SC_PREVWINDOW
Definition: winuser.h:2566
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:24
#define SC_CLOSE
Definition: winuser.h:2567
#define WM_CREATE
Definition: winuser.h:1590
#define SC_NEXTWINDOW
Definition: winuser.h:2565
#define WM_SYSCOMMAND
Definition: winuser.h:1723
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

Referenced by RegisterScreenSaverClass().

Variable Documentation

◆ fChildPreview

BOOL fChildPreview = FALSE

Definition at line 24 of file scrnsave.c.

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

◆ hMainInstance

◆ hMainWindow

HWND hMainWindow = NULL

Definition at line 23 of file scrnsave.c.

Referenced by LaunchScreenSaver().

◆ MyHelpMessage

UINT MyHelpMessage

Definition at line 32 of file scrnsave.c.

◆ pt_orig

POINT pt_orig
static

Definition at line 35 of file scrnsave.c.

Referenced by DefScreenSaverProc(), and SysScreenSaverProc().

◆ szAppName

TCHAR szAppName[APPNAMEBUFFERLEN]

Definition at line 27 of file scrnsave.c.

◆ szHelpFile

TCHAR szHelpFile[MAXFILELEN]

Definition at line 30 of file scrnsave.c.

Referenced by Control_LoadApplet(), and ICreateErrorInfoImpl_SetHelpFile().

◆ szIniFile

◆ szName

Definition at line 26 of file scrnsave.c.

◆ szNoHelpMemory

TCHAR szNoHelpMemory[BUFFLEN]

Definition at line 31 of file scrnsave.c.

◆ szScreenSaver

TCHAR szScreenSaver[22]

Definition at line 29 of file scrnsave.c.