ReactOS 0.4.15-dev-8096-ga0eec98
screensaver.c File Reference
#include "desk.h"
Include dependency graph for screensaver.c:

Go to the source code of this file.

Classes

struct  SCREEN_SAVER_ITEM
 
struct  _DATA
 

Macros

#define MAX_SCREENSAVERS   100
 

Typedefs

typedef struct _DATA DATA
 
typedef struct _DATAPDATA
 

Functions

static LPTSTR GetCurrentScreenSaverValue (LPTSTR lpValue)
 
static VOID SelectionChanged (HWND hwndDlg, PDATA pData)
 
LRESULT CALLBACK RedrawSubclassProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static VOID ShowScreenSaverPreview (IN LPDRAWITEMSTRUCT draw, IN PDATA pData)
 
static VOID SetScreenSaverPreviewBox (HWND hwndDlg, PDATA pData)
 
static BOOL WaitForSettingsDialog (HWND hwndDlg, HANDLE hProcess)
 
static VOID ScreenSaverConfig (HWND hwndDlg, PDATA pData)
 
static VOID ScreenSaverPreview (HWND hwndDlg, PDATA pData)
 
static VOID CheckRegScreenSaverIsSecure (HWND hwndDlg)
 
static BOOL AddScreenSaverItem (_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ SCREEN_SAVER_ITEM *ScreenSaverItem)
 
static BOOL AddScreenSaver (_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ LPCTSTR pszFilePath, _In_ LPCTSTR pszFileName)
 
static VOID SearchScreenSavers (_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ LPCTSTR pszSearchPath)
 
static VOID EnumScreenSavers (_In_ HWND hwndScreenSavers, _In_ PDATA pData)
 
static VOID SetScreenSaver (HWND hwndDlg, PDATA pData)
 
static BOOL OnInitDialog (HWND hwndDlg, PDATA pData)
 
INT_PTR CALLBACK ScreenSaverPageProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

static const TCHAR szPreviewWndClass [] = TEXT("SSDemoParent")
 

Macro Definition Documentation

◆ MAX_SCREENSAVERS

#define MAX_SCREENSAVERS   100

Definition at line 13 of file screensaver.c.

Typedef Documentation

◆ DATA

typedef struct _DATA DATA

◆ PDATA

typedef struct _DATA * PDATA

Function Documentation

◆ AddScreenSaver()

static BOOL AddScreenSaver ( _In_ HWND  hwndScreenSavers,
_In_ PDATA  pData,
_In_ LPCTSTR  pszFilePath,
_In_ LPCTSTR  pszFileName 
)
static

Definition at line 442 of file screensaver.c.

447{
448 SCREEN_SAVER_ITEM* ScreenSaverItem;
450 HRESULT hr;
451
452 if (pData->ScreenSaverCount >= MAX_SCREENSAVERS)
453 return FALSE;
454
455 ScreenSaverItem = pData->ScreenSaverItems + pData->ScreenSaverCount;
456
457 ScreenSaverItem->bIsScreenSaver = TRUE;
458
459 hModule = LoadLibraryEx(pszFilePath,
460 NULL,
462 if (hModule)
463 {
465 1,
466 ScreenSaverItem->szDisplayName,
467 _countof(ScreenSaverItem->szDisplayName)) == 0)
468 {
469 /* If the string does not exist, copy the file name */
470 hr = StringCbCopy(ScreenSaverItem->szDisplayName,
471 sizeof(ScreenSaverItem->szDisplayName),
473 if (FAILED(hr))
474 {
476 return FALSE;
477 }
478 /* Remove the .scr extension */
479 ScreenSaverItem->szDisplayName[_tcslen(pszFileName)-4] = _T('\0');
480 }
482 }
483 else
484 {
485 hr = StringCbCopy(ScreenSaverItem->szDisplayName,
486 sizeof(ScreenSaverItem->szDisplayName),
487 _T("Unknown"));
488 if (FAILED(hr))
489 return FALSE;
490 }
491
492 hr = StringCbCopy(ScreenSaverItem->szFilename,
493 sizeof(ScreenSaverItem->szFilename),
494 pszFilePath);
495 if (FAILED(hr))
496 return FALSE;
497
498 return AddScreenSaverItem(hwndScreenSavers, pData, ScreenSaverItem);
499}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BOOL AddScreenSaverItem(_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ SCREEN_SAVER_ITEM *ScreenSaverItem)
Definition: screensaver.c:415
#define MAX_SCREENSAVERS
Definition: screensaver.c:13
HMODULE hModule
Definition: animate.c:44
#define FreeLibrary(x)
Definition: compat.h:748
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:70
#define StringCbCopy
Definition: strsafe.h:155
TCHAR szDisplayName[256]
Definition: screensaver.c:21
TCHAR szFilename[MAX_PATH]
Definition: screensaver.c:20
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
#define _T(x)
Definition: vfdio.h:22
#define LoadLibraryEx
Definition: winbase.h:3863
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define DONT_RESOLVE_DLL_REFERENCES
Definition: winbase.h:341
#define LoadString
Definition: winuser.h:5819
#define _tcslen
Definition: xmlstorage.h:198

Referenced by OnInitDialog(), and SearchScreenSavers().

◆ AddScreenSaverItem()

static BOOL AddScreenSaverItem ( _In_ HWND  hwndScreenSavers,
_In_ PDATA  pData,
_In_ SCREEN_SAVER_ITEM ScreenSaverItem 
)
static

Definition at line 415 of file screensaver.c.

419{
420 UINT i;
421
422 if (pData->ScreenSaverCount >= MAX_SCREENSAVERS)
423 return FALSE;
424
425 i = SendMessage(hwndScreenSavers,
427 0,
428 (LPARAM)ScreenSaverItem->szDisplayName);
429 if ((i == CB_ERR) || (i == CB_ERRSPACE))
430 return FALSE;
431
432 SendMessage(hwndScreenSavers,
434 i,
435 (LPARAM)pData->ScreenSaverCount);
436
437 pData->ScreenSaverCount++;
438 return TRUE;
439}
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
unsigned int UINT
Definition: ndis.h:50
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_SETITEMDATA
Definition: winuser.h:1966
#define CB_ERRSPACE
Definition: winuser.h:2436
#define CB_ERR
Definition: winuser.h:2435
#define CB_ADDSTRING
Definition: winuser.h:1936
#define SendMessage
Definition: winuser.h:5843

Referenced by AddScreenSaver(), and EnumScreenSavers().

◆ CheckRegScreenSaverIsSecure()

static VOID CheckRegScreenSaverIsSecure ( HWND  hwndDlg)
static

Definition at line 370 of file screensaver.c.

371{
372 HKEY hKey;
373 TCHAR szBuffer[2];
374 DWORD bufferSize = sizeof(szBuffer);
375 DWORD varType = REG_SZ;
376 LONG result;
377
379 _T("Control Panel\\Desktop"),
380 0,
382 &hKey) == ERROR_SUCCESS)
383 {
385 _T("ScreenSaverIsSecure"),
386 0,
387 &varType,
388 (LPBYTE)szBuffer,
389 &bufferSize);
391
392 if (result == ERROR_SUCCESS)
393 {
394 if (_ttoi(szBuffer) == 1)
395 {
396 SendDlgItemMessage(hwndDlg,
400 0);
401 return;
402 }
403 }
404
405 SendDlgItemMessage(hwndDlg,
409 0);
410 }
411}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDC_SCREENS_USEPASSCHK
Definition: resource.h:44
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
size_t bufferSize
GLuint64EXT * result
Definition: glext.h:11304
#define REG_SZ
Definition: layer.c:22
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
long LONG
Definition: pedump.c:60
unsigned char * LPBYTE
Definition: typedefs.h:53
UINT_PTR WPARAM
Definition: windef.h:207
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
#define BST_UNCHECKED
Definition: winuser.h:199
#define BM_SETCHECK
Definition: winuser.h:1921
#define SendDlgItemMessage
Definition: winuser.h:5842
#define BST_CHECKED
Definition: winuser.h:197
char TCHAR
Definition: xmlstorage.h:189
#define _ttoi
Definition: xmlstorage.h:195

Referenced by OnInitDialog().

◆ EnumScreenSavers()

static VOID EnumScreenSavers ( _In_ HWND  hwndScreenSavers,
_In_ PDATA  pData 
)
static

Definition at line 544 of file screensaver.c.

547{
548 SCREEN_SAVER_ITEM* ScreenSaverItem;
549 PTCHAR pBackSlash;
550 TCHAR szSearchPath[MAX_PATH];
551 TCHAR szLocalPath[MAX_PATH];
552
553 /* Initialize the number of list items */
554 pData->ScreenSaverCount = 0;
555
556 /* Add the "(None)" item */
557 ScreenSaverItem = pData->ScreenSaverItems;
558
559 ScreenSaverItem->bIsScreenSaver = FALSE;
560
562 IDS_NONE,
563 ScreenSaverItem->szDisplayName,
564 _countof(ScreenSaverItem->szDisplayName));
565
566 AddScreenSaverItem(hwndScreenSavers, pData, ScreenSaverItem);
567
568 /* Add all the screensavers where the applet is stored */
569 GetModuleFileName(hApplet, szLocalPath, _countof(szLocalPath));
570 pBackSlash = _tcsrchr(szLocalPath, _T('\\'));
571 if (pBackSlash != NULL)
572 {
573 *pBackSlash = _T('\0');
574 SearchScreenSavers(hwndScreenSavers, pData, szLocalPath);
575 }
576
577 /* Add all the screensavers in the C:\ReactOS\System32 directory */
578 GetSystemDirectory(szSearchPath, _countof(szSearchPath));
579 if (pBackSlash != NULL && _tcsicmp(szSearchPath, szLocalPath) != 0)
580 SearchScreenSavers(hwndScreenSavers, pData, szSearchPath);
581
582 /* Add all the screensavers in the C:\ReactOS directory */
583 GetWindowsDirectory(szSearchPath, _countof(szSearchPath));
584 if (pBackSlash != NULL && _tcsicmp(szSearchPath, szLocalPath) != 0)
585 SearchScreenSavers(hwndScreenSavers, pData, szSearchPath);
586}
#define IDS_NONE
Definition: resource.h:133
HINSTANCE hApplet
Definition: access.c:17
static VOID SearchScreenSavers(_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ LPCTSTR pszSearchPath)
Definition: screensaver.c:502
#define MAX_PATH
Definition: compat.h:34
#define _tcsrchr
Definition: utility.h:116
char * PTCHAR
Definition: ntbasedef.h:476
#define GetWindowsDirectory
Definition: winbase.h:3857
#define GetSystemDirectory
Definition: winbase.h:3842
#define GetModuleFileName
Definition: winbase.h:3831
#define _tcsicmp
Definition: xmlstorage.h:205

Referenced by OnInitDialog().

◆ GetCurrentScreenSaverValue()

static LPTSTR GetCurrentScreenSaverValue ( LPTSTR  lpValue)
static

Definition at line 37 of file screensaver.c.

38{
39 HKEY hKey;
40 LPTSTR lpBuf = NULL;
42 LONG Ret;
43
45 _T("Control Panel\\Desktop"),
46 0,
48 &hKey);
49 if (Ret != ERROR_SUCCESS)
50 return NULL;
51
53 lpValue,
54 0,
55 &Type,
56 NULL,
57 &BufSize);
58 if (Ret == ERROR_SUCCESS)
59 {
60 lpBuf = HeapAlloc(GetProcessHeap(), 0, BufSize);
61 if (lpBuf)
62 {
64 lpValue,
65 0,
66 &Type,
67 (LPBYTE)lpBuf,
68 &BufSize);
69 if (Ret != ERROR_SUCCESS)
70 {
71 HeapFree(GetProcessHeap(), 0, lpBuf);
72 lpBuf = NULL;
73 }
74 }
75 }
76
78
79 return lpBuf;
80}
#define BufSize
Definition: FsRtlTunnel.c:28
Type
Definition: Type.h:7
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define KEY_READ
Definition: nt_native.h:1023
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by OnInitDialog().

◆ OnInitDialog()

static BOOL OnInitDialog ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 657 of file screensaver.c.

658{
659 HWND hwndSSCombo = GetDlgItem(hwndDlg, IDC_SCREENS_LIST);
660 LPTSTR pSsValue;
661 INT iCurSs;
662 WNDCLASS wc = {0};
663
665 if (!pData)
666 {
667 EndDialog(hwndDlg, -1);
668 return FALSE;
669 }
670
672 wc.hInstance = hApplet;
673 wc.hCursor = NULL;
676
677 if (RegisterClass(&wc))
678 {
679 HWND hParent = GetDlgItem(hwndDlg, IDC_SCREENS_PREVIEW);
680 HWND hChild;
681
682 if (hParent != NULL)
683 {
684 pData->OldPreviewProc = (WNDPROC)GetWindowLongPtr(hParent, GWLP_WNDPROC);
687 }
688
691 0, 0, 0, 0, hParent,
692 NULL, hApplet, NULL);
693 if (hChild != NULL)
694 {
695 RECT rc;
696 GetClientRect(hParent, &rc);
697 rc.left += MONITOR_LEFT;
698 rc.top += MONITOR_TOP;
700 }
701
702 pData->ScreenSaverPreviewParent = hChild;
703 }
704
706
707 pData->Selection = -1;
708
709 SendDlgItemMessage(hwndDlg,
712 0,
713 MAKELONG(240, 1));
714
715 EnumScreenSavers(hwndSSCombo, pData);
716
718
719 /* Set the current screensaver in the combo box */
720 iCurSs = 0; // Default to "(None)"
721 pSsValue = GetCurrentScreenSaverValue(_T("SCRNSAVE.EXE"));
722 if (pSsValue)
723 {
724 BOOL bFound = FALSE;
725 INT i;
726
727 /* Find whether the current screensaver is in the list */
728 for (i = 0; i < pData->ScreenSaverCount; i++)
729 {
730 if (!_tcsicmp(pSsValue, pData->ScreenSaverItems[i].szFilename))
731 {
732 bFound = TRUE;
733 break;
734 }
735 }
736
737 if (!bFound)
738 {
739 /* The current screensaver is not in the list: add it */
740 // i = pData->ScreenSaverCount;
741 bFound = AddScreenSaver(hwndSSCombo, pData, pSsValue, _T("SCRNSAVE.EXE"));
742 if (bFound)
743 i = pData->ScreenSaverCount - 1;
744 }
745
746 HeapFree(GetProcessHeap(), 0, pSsValue);
747
748 if (bFound)
749 {
750 /* The current screensaver should be in the list: select it */
751 iCurSs = SendMessage(hwndSSCombo,
753 -1,
754 (LPARAM)pData->ScreenSaverItems[i].szDisplayName);
755 if (iCurSs == CB_ERR)
756 iCurSs = 0; // Default to "(None)"
757 }
758 }
759 SendMessage(hwndSSCombo, CB_SETCURSEL, iCurSs, 0);
760
761 /* Set the current timeout */
762 pSsValue = GetCurrentScreenSaverValue(_T("ScreenSaveTimeOut"));
763 if (pSsValue)
764 {
765 UINT Time = _ttoi(pSsValue) / 60;
766
767 HeapFree(GetProcessHeap(), 0, pSsValue);
768
769 SendDlgItemMessage(hwndDlg,
772 0,
773 Time);
774 }
775
776 SelectionChanged(hwndDlg, pData);
777
778 return TRUE;
779}
#define MONITOR_HEIGHT
Definition: desk.h:77
#define MONITOR_LEFT
Definition: desk.h:71
#define MONITOR_TOP
Definition: desk.h:72
#define MONITOR_WIDTH
Definition: desk.h:76
#define IDC_SCREENS_PREVIEW
Definition: resource.h:39
#define IDC_SCREENS_TIME
Definition: resource.h:46
#define IDC_SCREENS_LIST
Definition: resource.h:40
static LPTSTR GetCurrentScreenSaverValue(LPTSTR lpValue)
Definition: screensaver.c:37
static VOID SelectionChanged(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:84
static VOID EnumScreenSavers(_In_ HWND hwndScreenSavers, _In_ PDATA pData)
Definition: screensaver.c:544
static const TCHAR szPreviewWndClass[]
Definition: screensaver.c:15
static VOID CheckRegScreenSaverIsSecure(HWND hwndDlg)
Definition: screensaver.c:370
LRESULT CALLBACK RedrawSubclassProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: screensaver.c:110
static BOOL AddScreenSaver(_In_ HWND hwndScreenSavers, _In_ PDATA pData, _In_ LPCTSTR pszFilePath, _In_ LPCTSTR pszFileName)
Definition: screensaver.c:442
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
static HTREEITEM hChild
Definition: treeview.c:381
static PLARGE_INTEGER Time
Definition: time.c:105
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define WS_CHILD
Definition: pedump.c:617
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define UDM_SETRANGE
Definition: commctrl.h:2141
#define UDM_SETPOS32
Definition: commctrl.h:2155
#define DefWindowProc
Definition: ros2win.h:31
HBRUSH hbrBackground
Definition: winuser.h:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_WNDPROC
Definition: treelist.c:66
#define GWLP_USERDATA
Definition: treelist.c:63
int32_t INT
Definition: typedefs.h:58
#define MAKELONG(a, b)
Definition: typedefs.h:249
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BLACK_BRUSH
Definition: wingdi.h:896
#define CreateWindowEx
Definition: winuser.h:5755
#define DWLP_USER
Definition: winuser.h:872
#define CB_SETCURSEL
Definition: winuser.h:1961
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1940
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegisterClass
Definition: winuser.h:5836
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by ScreenSaverPageProc().

◆ RedrawSubclassProc()

LRESULT CALLBACK RedrawSubclassProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 110 of file screensaver.c.

114{
115 HWND hwnd;
116 PDATA pData;
117 LRESULT Ret = FALSE;
118
120 if (!pData)
121 return Ret;
122
123 Ret = CallWindowProc(pData->OldPreviewProc, hwndDlg, uMsg, wParam, lParam);
124
125 if (uMsg == WM_PAINT)
126 {
127 hwnd = pData->ScreenSaverPreviewParent;
128 if (hwnd)
130 }
131
132 return Ret;
133}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct _DATA * PDATA
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LRESULT
Definition: windef.h:209
#define WM_PAINT
Definition: winuser.h:1620
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define CallWindowProc
Definition: winuser.h:5735
#define RDW_ERASE
Definition: winuser.h:1211
#define RDW_ALLCHILDREN
Definition: winuser.h:1221
#define RDW_INVALIDATE
Definition: winuser.h:1214

Referenced by OnInitDialog().

◆ ScreenSaverConfig()

static VOID ScreenSaverConfig ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 271 of file screensaver.c.

272{
273 HRESULT hr;
274 STARTUPINFO si;
276 TCHAR szCmdline[2048];
277
278 if (pData->Selection < 1)
279 return;
280
281 hr = StringCbPrintf(szCmdline, sizeof(szCmdline),
282 TEXT("%s /c:%Iu"),
283 pData->ScreenSaverItems[pData->Selection].szFilename,
284 (ULONG_PTR)hwndDlg);
285 if (FAILED(hr))
286 return;
287
288 ZeroMemory(&si, sizeof(si));
289 si.cb = sizeof(si);
290 ZeroMemory(&pi, sizeof(pi));
292 szCmdline,
293 NULL,
294 NULL,
295 FALSE,
296 0,
297 NULL,
298 NULL,
299 &si,
300 &pi))
301 {
302 /* Kill off the previous preview process */
303 if (pData->PrevWindowPi.hProcess)
304 {
305 TerminateProcess(pData->PrevWindowPi.hProcess, 0);
306 CloseHandle(pData->PrevWindowPi.hProcess);
307 CloseHandle(pData->PrevWindowPi.hThread);
308 pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL;
309 }
310
311 if (WaitForSettingsDialog(hwndDlg, pi.hProcess))
313
314 CloseHandle(pi.hProcess);
315 CloseHandle(pi.hThread);
316 }
317}
static VOID SetScreenSaverPreviewBox(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:178
static BOOL WaitForSettingsDialog(HWND hwndDlg, HANDLE hProcess)
Definition: screensaver.c:227
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
#define TEXT(s)
Definition: k32.h:26
static refpint_t pi[]
Definition: server.c:96
#define StringCbPrintf
Definition: strsafe.h:544
DWORD cb
Definition: winbase.h:831
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CreateProcess
Definition: winbase.h:3758
#define ZeroMemory
Definition: winbase.h:1712

Referenced by ScreenSaverPageProc().

◆ ScreenSaverPageProc()

INT_PTR CALLBACK ScreenSaverPageProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 783 of file screensaver.c.

787{
788 PDATA pData;
789
791
792 switch (uMsg)
793 {
794 case WM_INITDIALOG:
795 {
796 OnInitDialog(hwndDlg, pData);
797 break;
798 }
799
800 case WM_DESTROY:
801 {
802 if (pData->ScreenSaverPreviewParent)
803 {
806 (LONG_PTR)pData->OldPreviewProc);
807 DestroyWindow(pData->ScreenSaverPreviewParent);
808 pData->ScreenSaverPreviewParent = NULL;
809 }
811 if (pData->PrevWindowPi.hProcess)
812 {
813 TerminateProcess(pData->PrevWindowPi.hProcess, 0);
814 CloseHandle(pData->PrevWindowPi.hProcess);
815 CloseHandle(pData->PrevWindowPi.hThread);
816 }
818 break;
819 }
820
821 case WM_ENDSESSION:
822 {
824 break;
825 }
826
827 case WM_DRAWITEM:
828 {
829 LPDRAWITEMSTRUCT lpDrawItem;
830 lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
831
832 if (lpDrawItem->CtlID == IDC_SCREENS_PREVIEW)
833 ShowScreenSaverPreview(lpDrawItem, pData);
834 break;
835 }
836
837 case WM_COMMAND:
838 {
839 DWORD controlId = LOWORD(wParam);
841
842 switch (controlId)
843 {
844 case IDC_SCREENS_LIST:
845 {
847 {
848 SelectionChanged(hwndDlg, pData);
850 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
851 }
852 break;
853 }
854
856 {
857 if (command == EN_CHANGE)
858 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
859 break;
860 }
861
862 case IDC_SCREENS_POWER_BUTTON: // Start Powercfg.Cpl
863 {
864 if (command == BN_CLICKED)
865 WinExec("rundll32 shell32.dll,Control_RunDLL powercfg.cpl",SW_SHOWNORMAL);
866 break;
867 }
868
869 case IDC_SCREENS_TESTSC: // Screensaver Preview
870 {
871 if (command == BN_CLICKED)
872 {
873 ScreenSaverPreview(hwndDlg, pData);
875 }
876 break;
877 }
878
879 case IDC_SCREENS_SETTINGS: // Screensaver Settings
880 {
881 if (command == BN_CLICKED)
882 ScreenSaverConfig(hwndDlg, pData);
883 break;
884 }
885
886 case IDC_SCREENS_USEPASSCHK: // Screensaver Is Secure
887 {
888 if (command == BN_CLICKED)
889 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
890 break;
891 }
892 }
893 break;
894 }
895
896 case WM_NOTIFY:
897 {
898 LPNMHDR lpnm = (LPNMHDR)lParam;
899
900 switch(lpnm->code)
901 {
902 case PSN_APPLY:
903 {
904 SetScreenSaver(hwndDlg, pData);
905 return TRUE;
906 }
907
908 case PSN_SETACTIVE:
909 {
910 /* Enable screensaver preview support */
912 break;
913 }
914
915 case PSN_KILLACTIVE:
916 {
917 /* Kill running preview screensaver */
918 if (pData->PrevWindowPi.hProcess)
919 {
920 TerminateProcess(pData->PrevWindowPi.hProcess, 0);
921 CloseHandle(pData->PrevWindowPi.hProcess);
922 CloseHandle(pData->PrevWindowPi.hThread);
923 pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL;
924 }
925 break;
926 }
927 }
928 }
929 break;
930 }
931
932 return FALSE;
933}
#define IDC_SCREENS_TIMEDELAY
Definition: resource.h:45
#define IDC_SCREENS_POWER_BUTTON
Definition: resource.h:41
#define IDC_SCREENS_TESTSC
Definition: resource.h:43
#define IDC_SCREENS_SETTINGS
Definition: resource.h:42
static VOID ShowScreenSaverPreview(IN LPDRAWITEMSTRUCT draw, IN PDATA pData)
Definition: screensaver.c:137
static VOID ScreenSaverPreview(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:323
static VOID SetScreenSaver(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:590
static BOOL OnInitDialog(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:657
static VOID ScreenSaverConfig(HWND hwndDlg, PDATA pData)
Definition: screensaver.c:271
UINT WINAPI DECLSPEC_HOTPATCH WinExec(LPCSTR lpCmdLine, UINT uCmdShow)
Definition: proc.c:4773
#define LOWORD(l)
Definition: pedump.c:82
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_KILLACTIVE
Definition: prsht.h:116
#define PSN_APPLY
Definition: prsht.h:117
#define PSN_SETACTIVE
Definition: prsht.h:115
#define WM_NOTIFY
Definition: richedit.h:61
UINT code
Definition: winuser.h:3159
#define HIWORD(l)
Definition: typedefs.h:247
#define SW_SHOWNORMAL
Definition: winuser.h:770
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
#define WM_COMMAND
Definition: winuser.h:1740
#define UnregisterClass
Definition: winuser.h:5861
#define WM_INITDIALOG
Definition: winuser.h:1739
#define WM_DRAWITEM
Definition: winuser.h:1645
#define CBN_SELCHANGE
Definition: winuser.h:1979
struct tagNMHDR * LPNMHDR
HWND WINAPI GetParent(_In_ HWND)
#define BN_CLICKED
Definition: winuser.h:1925
#define WM_DESTROY
Definition: winuser.h:1609
#define WM_ENDSESSION
Definition: winuser.h:1627
BOOL WINAPI DestroyWindow(_In_ HWND)
#define EN_CHANGE
Definition: winuser.h:2022

◆ ScreenSaverPreview()

static VOID ScreenSaverPreview ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 323 of file screensaver.c.

324{
325 HRESULT hr;
326 STARTUPINFO si;
328 TCHAR szCmdline[2048];
329
330 if (pData->Selection < 1)
331 return;
332
333 /* Kill off the previous preview process */
334 if (pData->PrevWindowPi.hProcess)
335 {
336 TerminateProcess(pData->PrevWindowPi.hProcess, 0);
337 CloseHandle(pData->PrevWindowPi.hProcess);
338 CloseHandle(pData->PrevWindowPi.hThread);
339 pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL;
340 }
341
342 hr = StringCbPrintf(szCmdline, sizeof(szCmdline),
343 TEXT("%s /s"),
344 pData->ScreenSaverItems[pData->Selection].szFilename);
345 if (FAILED(hr))
346 return;
347
348 ZeroMemory(&si, sizeof(si));
349 si.cb = sizeof(si);
350 ZeroMemory(&pi, sizeof(pi));
352 szCmdline,
353 NULL,
354 NULL,
355 FALSE,
356 0,
357 NULL,
358 NULL,
359 &si,
360 &pi))
361 {
363 CloseHandle(pi.hProcess);
364 CloseHandle(pi.hThread);
365 }
366}
#define INFINITE
Definition: serial.h:102
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82

Referenced by ScreenSaverPageProc().

◆ SearchScreenSavers()

static VOID SearchScreenSavers ( _In_ HWND  hwndScreenSavers,
_In_ PDATA  pData,
_In_ LPCTSTR  pszSearchPath 
)
static

Definition at line 502 of file screensaver.c.

506{
507 HRESULT hr;
509 HANDLE hFind;
511
513 TEXT("%s\\*.scr"), pszSearchPath);
514 if (FAILED(hr))
515 return;
516
517 hFind = FindFirstFile(szFilePath, &fd);
518 if (hFind == INVALID_HANDLE_VALUE)
519 return;
520
521 do
522 {
523 /* Don't add any hidden screensavers */
524 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
525 continue;
526
527 if (pData->ScreenSaverCount >= MAX_SCREENSAVERS)
528 break;
529
531 TEXT("%s\\%s"), pszSearchPath, fd.cFileName);
532 if (FAILED(hr))
533 break;
534
535 if (!AddScreenSaver(hwndScreenSavers, pData, szFilePath, fd.cFileName))
536 break;
537
538 } while (FindNextFile(hFind, &fd));
539
540 FindClose(hFind);
541}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
static WCHAR szFilePath[]
Definition: qotd.c:14
static int fd
Definition: io.c:51
#define FindNextFile
Definition: winbase.h:3788
#define FindFirstFile
Definition: winbase.h:3782

Referenced by EnumScreenSavers().

◆ SelectionChanged()

static VOID SelectionChanged ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 84 of file screensaver.c.

85{
86 HWND hwndCombo;
88 INT i;
89
90 hwndCombo = GetDlgItem(hwndDlg, IDC_SCREENS_LIST);
91
92 i = (INT)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
93 i = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
94
95 pData->Selection = i;
96
97 bEnable = (i != 0);
98
106}
#define IDC_MINTEXT
Definition: resource.h:48
#define IDC_WAITTEXT
Definition: resource.h:47
#define INT
Definition: polytest.cpp:20
_In_ BOOL bEnable
Definition: winddi.h:3426
#define CB_GETITEMDATA
Definition: winuser.h:1950
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define CB_GETCURSEL
Definition: winuser.h:1943

Referenced by OnInitDialog(), and ScreenSaverPageProc().

◆ SetScreenSaver()

static VOID SetScreenSaver ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 590 of file screensaver.c.

591{
592 HKEY regKey;
593
595 _T("Control Panel\\Desktop"),
596 0,
598 &regKey) == ERROR_SUCCESS)
599 {
600 INT Time;
601 BOOL bRet;
602 TCHAR Sec;
603 UINT Ret;
604
605 /* Set the screensaver */
606 if (pData->ScreenSaverItems[pData->Selection].bIsScreenSaver)
607 {
608 SIZE_T Length = (_tcslen(pData->ScreenSaverItems[pData->Selection].szFilename) + 1) * sizeof(TCHAR);
609 RegSetValueEx(regKey,
610 _T("SCRNSAVE.EXE"),
611 0,
612 REG_SZ,
613 (PBYTE)pData->ScreenSaverItems[pData->Selection].szFilename,
614 (DWORD)Length);
615
617 }
618 else
619 {
620 /* Windows deletes the value if no screensaver is set */
621 RegDeleteValue(regKey, _T("SCRNSAVE.EXE"));
622
624 }
625
626 /* Set the secure value */
627 Ret = SendDlgItemMessage(hwndDlg,
630 0,
631 0);
632 Sec = (Ret == BST_CHECKED) ? _T('1') : _T('0');
633 RegSetValueEx(regKey,
634 _T("ScreenSaverIsSecure"),
635 0,
636 REG_SZ,
637 (PBYTE)&Sec,
638 sizeof(TCHAR));
639
640 /* Set the screensaver time delay */
641 Time = GetDlgItemInt(hwndDlg,
643 &bRet,
644 FALSE);
645 if (Time == 0)
646 Time = 1;
647 Time *= 60; // Convert to seconds
648
650
651 RegCloseKey(regKey);
652 }
653}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BYTE * PBYTE
Definition: pedump.c:66
UINT Sec[]
Definition: powershemes.c:41
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RegSetValueEx
Definition: winreg.h:533
#define RegDeleteValue
Definition: winreg.h:508
#define SPI_SETSCREENSAVEACTIVE
Definition: winuser.h:1366
#define SPIF_SENDCHANGE
Definition: winuser.h:1572
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1571
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
UINT WINAPI GetDlgItemInt(_In_ HWND, _In_ int, _Out_opt_ PBOOL, _In_ BOOL)
#define SystemParametersInfo
Definition: winuser.h:5858
#define SPI_SETSCREENSAVETIMEOUT
Definition: winuser.h:1364
#define BM_GETCHECK
Definition: winuser.h:1918

Referenced by ScreenSaverPageProc().

◆ SetScreenSaverPreviewBox()

static VOID SetScreenSaverPreviewBox ( HWND  hwndDlg,
PDATA  pData 
)
static

Definition at line 178 of file screensaver.c.

179{
180 HWND hPreview = pData->ScreenSaverPreviewParent;
181 HRESULT hr;
182 STARTUPINFO si;
183 TCHAR szCmdline[2048];
184
185 /* Kill off the previous preview process */
186 if (pData->PrevWindowPi.hProcess)
187 {
188 TerminateProcess(pData->PrevWindowPi.hProcess, 0);
189 CloseHandle(pData->PrevWindowPi.hProcess);
190 CloseHandle(pData->PrevWindowPi.hThread);
191 pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL;
192 }
193 ShowWindow(pData->ScreenSaverPreviewParent, SW_HIDE);
194
195 if (pData->Selection < 1)
196 return;
197
198 hr = StringCbPrintf(szCmdline, sizeof(szCmdline),
199 TEXT("%s /p %Iu"),
200 pData->ScreenSaverItems[pData->Selection].szFilename,
201 (ULONG_PTR)hPreview);
202 if (FAILED(hr))
203 return;
204
205 ZeroMemory(&si, sizeof(si));
206 si.cb = sizeof(si);
207 ZeroMemory(&pData->PrevWindowPi, sizeof(pData->PrevWindowPi));
208
209 ShowWindow(pData->ScreenSaverPreviewParent, SW_SHOW);
210
211 if (!CreateProcess(NULL,
212 szCmdline,
213 NULL,
214 NULL,
215 FALSE,
216 0,
217 NULL,
218 NULL,
219 &si,
220 &pData->PrevWindowPi))
221 {
222 pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL;
223 }
224}
#define SW_HIDE
Definition: winuser.h:768
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SW_SHOW
Definition: winuser.h:775

Referenced by ScreenSaverConfig(), and ScreenSaverPageProc().

◆ ShowScreenSaverPreview()

static VOID ShowScreenSaverPreview ( IN LPDRAWITEMSTRUCT  draw,
IN PDATA  pData 
)
static

Definition at line 137 of file screensaver.c.

138{
139 HBRUSH hBrush;
140 HDC hDC;
141 HGDIOBJ hOldObj;
142 RECT rcItem = {
147 };
148
149 hDC = CreateCompatibleDC(draw->hDC);
151
152 if (!IsWindowVisible(pData->ScreenSaverPreviewParent))
153 {
154 /* FIXME: Draw static bitmap inside monitor. */
156 FillRect(hDC, &rcItem, hBrush);
157 DeleteObject(hBrush);
158 }
159
160 GdiTransparentBlt(draw->hDC,
161 draw->rcItem.left, draw->rcItem.top,
162 draw->rcItem.right - draw->rcItem.left + 1,
163 draw->rcItem.bottom - draw->rcItem.top + 1,
164 hDC,
165 0, 0,
168
169 SelectObject(hDC, hOldObj);
170 DeleteDC(hDC);
171}
static HDC hDC
Definition: 3dtext.c:33
GLOBAL_DATA g_GlobalData
Definition: background.c:70
#define MONITOR_BOTTOM
Definition: desk.h:74
#define MONITOR_ALPHA
Definition: desk.h:79
#define MONITOR_RIGHT
Definition: desk.h:73
pKey DeleteObject()
static HDC
Definition: imagelist.c:92
LONG bmMonHeight
Definition: desk.h:164
LONG bmMonWidth
Definition: desk.h:163
COLORREF desktop_color
Definition: desk.h:159
HBITMAP hMonitorBitmap
Definition: desk.h:162
BOOL WINAPI GdiTransparentBlt(HDC hdcDst, int xDst, int yDst, int wDst, int hDst, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, UINT crTransparent)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI IsWindowVisible(_In_ HWND)

Referenced by ScreenSaverPageProc().

◆ WaitForSettingsDialog()

static BOOL WaitForSettingsDialog ( HWND  hwndDlg,
HANDLE  hProcess 
)
static

Definition at line 227 of file screensaver.c.

229{
230 DWORD dwResult;
231 MSG msg;
232
233 while (TRUE)
234 {
235 dwResult = MsgWaitForMultipleObjects(1,
236 &hProcess,
237 FALSE,
238 INFINITE,
240 if (dwResult == WAIT_OBJECT_0 + 1)
241 {
242 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
243 {
244 if (msg.message == WM_QUIT)
245 {
246 return FALSE;
247 }
248 if (IsDialogMessage(hwndDlg, &msg))
249 {
252 }
253 }
254 }
255 else if (dwResult == WAIT_OBJECT_0)
256 {
257 return TRUE;
258 }
259 else
260 {
261 return FALSE;
262 }
263 }
264}
#define msg(x)
Definition: auth_time.c:54
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WM_QUIT
Definition: winuser.h:1623
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define IsDialogMessage
Definition: winuser.h:5809
#define QS_ALLINPUT
Definition: winuser.h:903
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
#define PM_REMOVE
Definition: winuser.h:1196
#define PeekMessage
Definition: winuser.h:5830
#define DispatchMessage
Definition: winuser.h:5765

Referenced by ScreenSaverConfig().

Variable Documentation

◆ szPreviewWndClass

const TCHAR szPreviewWndClass[] = TEXT("SSDemoParent")
static

Definition at line 15 of file screensaver.c.

Referenced by OnInitDialog(), and ScreenSaverPageProc().