ReactOS  0.4.13-dev-563-g0561610
screensave.c
Go to the documentation of this file.
1 //
2 // screensave.c
3 //
4 // Entrypoint for a win32 screensaver
5 //
6 // NOTES: Screen savers don't like being UPX'd (compressed). Don't
7 // know why, it just is. C-runtime has been stripped with
8 // "libctiny.lib".
9 //
10 // v1.0 1/12/2003 J Brown
11 //
12 #include <windows.h>
13 #include <windowsx.h>
14 #include <tchar.h>
15 #include "globals.h"
16 #include "message.h"
17 #include "matrix.h"
18 #include "resource.h"
19 
20 //#pragma comment(lib, "libctiny.lib")
21 //#pragma comment(linker, "/OPT:NOWIN98")
22 
23 //
24 // Added: Multimonitor support!!
25 //
26 HMONITOR (WINAPI * pfnEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
27 BOOL (WINAPI * pfnGetMonitorInfo)(HMONITOR, LPMONITORINFO);
28 
29 //
30 // Callback function for EnumDisplayMonitors API. Use this function
31 // to kickstart a screen-saver window for each monitor in the system
32 //
33 BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, RECT *rcMonitor, LPARAM Param)
34 {
35  HWND hwnd;
36 
37  // Create a screensaver on this monitor!
38  hwnd = CreateScreenSaveWnd((HWND)Param, rcMonitor);
39 
40  // For some reason windows always places this window at 0,0...
41  // position it ourselves
42  SetWindowPos(hwnd, 0, rcMonitor->left, rcMonitor->top, 0, 0,
44 
45  return TRUE;
46 }
47 
48 //
49 // Start screen saver!
50 //
52 {
53  HMODULE hUser32;
54  UINT nPreviousState;
55  MSG msg;
56 
58 
59  SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);
60 
61  // Dynamically locate API call from USER32 - not present in all versions
62  hUser32 = GetModuleHandle(_T("USER32.DLL"));
63  pfnEnumDisplayMonitors = (PVOID)GetProcAddress(hUser32, "EnumDisplayMonitors");
64 
65  // If we're running Win2k+ then the API is available...so call it!
66  if(pfnEnumDisplayMonitors && hwndParent == 0)
67  {
68  pfnEnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0);
69  }
70  // Otherwise simulate by calling enum-proc manually
71  else
72  {
73  RECT rect;
74 
75  rect.left = 0;
77  rect.top = 0;
79 
81  }
82 
83  // run message loop to handle all screen-saver windows
84  while(GetMessage(&msg, NULL,0,0))
85  {
88  }
89 
90  SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
91 
92  return TRUE;
93 }
94 
95 //
96 // Look for any options Windows has passed to us:
97 //
98 // -a <hwnd> (set password)
99 // -s (screensave)
100 // -p <hwnd> (preview)
101 // -c <hwnd> (configure)
102 //
104 {
105  UCHAR ch = *szCmdLine++;
106 
107  if(ch == '-' || ch == '/')
108  ch = *szCmdLine++;
109 
110  if(ch >= 'A' && ch <= 'Z')
111  ch += 'a' - 'A'; //convert to lower case
112 
113  *chOption = ch;
114  ch = *szCmdLine++;
115 
116  if(ch == ':')
117  ch = *szCmdLine++;
118 
119  while(ch == ' ' || ch == '\t')
120  ch = *szCmdLine++;
121 
122  if(isdigit(ch))
123  {
124  ULONG_PTR i = _wtoi(szCmdLine - 1);
125  *hwndParent = (HWND)i;
126  }
127  else
128  *hwndParent = NULL;
129 }
130 
131 //
132 // Entrypoint for screen-saver: it's just a normal win32 app!
133 //
134 int CALLBACK wWinMain (HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int iCmdShow)
135 {
137  UCHAR chOption;
138 
139  // Make sure that only 1 instance runs at a time -
140  // Win98 seems to want us to restart every 5 seconds!!
142  {
143  return 0;
144  }
145 
146  LoadSettings();
147 
148  ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
149 
150  switch(chOption)
151  {
152  case 's': return ScreenSaver(NULL); // screen save
153  case 'p': return ScreenSaver(hwndParent); // preview in small window
154  case 'a': return ChangePassword(hwndParent); // ask for password
155  case 'c': return Configure(hwndParent); // configuration dialog
156  default: return Configure(hwndParent); // configuration dialog
157  }
158 
159  return 0;
160 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
VOID ParseCommandLine(LPWSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
Definition: screensave.c:103
BOOL ChangePassword(HWND hwnd)
Definition: password.c:48
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
BOOL ScreenSaver(HWND hwndParent)
Definition: screensave.c:51
#define SystemParametersInfo
Definition: winuser.h:5724
LONG top
Definition: windef.h:292
HANDLE HWND
Definition: compat.h:13
LONG left
Definition: windef.h:291
#define SWP_NOZORDER
Definition: winuser.h:1232
& rect
Definition: startmenu.cpp:1413
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, RECT *rcMonitor, LPARAM Param)
Definition: screensave.c:33
uint32_t ULONG_PTR
Definition: typedefs.h:63
MONITORENUMPROC
Definition: screensave.c:26
LPARAM
Definition: screensave.c:26
#define SM_CXSCREEN
Definition: winuser.h:949
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void LoadSettings(void)
Definition: settings.c:53
unsigned int BOOL
Definition: ntddk_ex.h:94
LPCRECT
Definition: screensave.c:26
smooth NULL
Definition: ftsmooth.c:416
static HWND hwndParent
Definition: cryptui.c:300
LONG_PTR LPARAM
Definition: windef.h:208
void * PVOID
Definition: retypes.h:9
#define isdigit(c)
Definition: acclib.h:68
static LRESULT Configure(const CodecInfo *pi, HWND hWnd)
Definition: msrle32.c:1192
#define SM_CYSCREEN
Definition: winuser.h:950
#define _T(x)
Definition: vfdio.h:22
#define SWP_NOACTIVATE
Definition: winuser.h:1227
HMONITOR(WINAPI *pfnEnumDisplayMonitors)(HDC
#define FindWindowEx
Definition: winuser.h:5644
#define WINAPI
Definition: msvc.h:8
int WINAPI GetSystemMetrics(_In_ int)
HWND CreateScreenSaveWnd(HWND hwndParent, RECT *rect)
Definition: matrix.c:390
unsigned char UCHAR
Definition: xmlstorage.h:181
int CALLBACK wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int iCmdShow)
Definition: screensave.c:134
#define SWP_NOSIZE
Definition: winuser.h:1230
void InitScreenSaveClass(BOOL fPreview)
Definition: matrix.c:421
HINSTANCE hInst
Definition: dxdiag.c:13
#define GetModuleHandle
Definition: winbase.h:3641
BOOL(WINAPI *pfnGetMonitorInfo)(HMONITOR
unsigned int UINT
Definition: ndis.h:50
#define GetMessage
Definition: winuser.h:5656
#define SWP_SHOWWINDOW
Definition: winuser.h:1233
#define APPNAME
Definition: 3dtext.c:40
#define msg(x)
Definition: auth_time.c:54
LPMONITORINFO
Definition: screensave.c:27
#define GetProcAddress(x, y)
Definition: compat.h:410
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
WCHAR * LPWSTR
Definition: xmlstorage.h:184