ReactOS 0.4.15-dev-8231-g29a56f3
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//
26HMONITOR (WINAPI * pfnEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
27BOOL (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//
33BOOL 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//
134int 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}
#define APPNAME
Definition: 3dtext.c:40
#define isdigit(c)
Definition: acclib.h:68
#define msg(x)
Definition: auth_time.c:54
HANDLE HMONITOR
Definition: axextend.idl:431
void LoadSettings(void)
Definition: settings.c:53
static HWND hwndParent
Definition: cryptui.c:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE HWND
Definition: compat.h:19
#define GetProcAddress(x, y)
Definition: compat.h:753
#define CALLBACK
Definition: compat.h:35
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
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
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
BOOL ChangePassword(HWND hwnd)
Definition: password.c:48
HWND CreateScreenSaveWnd(HWND hwndParent, RECT *rect)
Definition: matrix.c:390
void InitScreenSaveClass()
static HDC
Definition: imagelist.c:92
static LRESULT Configure(const CodecInfo *pi, HWND hWnd)
Definition: msrle32.c:1192
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
int CALLBACK wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int iCmdShow)
Definition: screensave.c:134
LPARAM
Definition: screensave.c:26
LPMONITORINFO
Definition: screensave.c:27
VOID ParseCommandLine(LPWSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
Definition: screensave.c:103
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, RECT *rcMonitor, LPARAM Param)
Definition: screensave.c:33
BOOL ScreenSaver(HWND hwndParent)
Definition: screensave.c:51
LPCRECT
Definition: screensave.c:26
MONITORENUMPROC
Definition: screensave.c:26
& rect
Definition: startmenu.cpp:1413
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define _T(x)
Definition: vfdio.h:22
#define GetModuleHandle
Definition: winbase.h:3827
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define WINAPI
Definition: msvc.h:6
#define SWP_NOACTIVATE
Definition: winuser.h:1242
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define SM_CYSCREEN
Definition: winuser.h:960
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOSIZE
Definition: winuser.h:1245
#define FindWindowEx
Definition: winuser.h:5787
#define GetMessage
Definition: winuser.h:5799
#define SWP_SHOWWINDOW
Definition: winuser.h:1248
#define SM_CXSCREEN
Definition: winuser.h:959
#define DispatchMessage
Definition: winuser.h:5774
#define SWP_NOZORDER
Definition: winuser.h:1247
#define SystemParametersInfo
Definition: winuser.h:5867
int WINAPI GetSystemMetrics(_In_ int)
unsigned char UCHAR
Definition: xmlstorage.h:181
WCHAR * LPWSTR
Definition: xmlstorage.h:184