ReactOS  0.4.15-dev-509-g96a357b
shutdown.c File Reference
#include "msgina.h"
#include <powrprof.h>
#include <wingdi.h>
Include dependency graph for shutdown.c:

Go to the source code of this file.

Classes

struct  _SHUTDOWN_DLG_CONTEXT
 

Macros

#define WLX_SHUTDOWN_STATE_LOGOFF   0x01
 
#define WLX_SHUTDOWN_STATE_POWER_OFF   0x02
 
#define WLX_SHUTDOWN_STATE_REBOOT   0x04
 
#define WLX_SHUTDOWN_STATE_SLEEP   0x10
 
#define WLX_SHUTDOWN_STATE_HIBERNATE   0x40
 

Typedefs

typedef struct _SHUTDOWN_DLG_CONTEXT SHUTDOWN_DLG_CONTEXT
 
typedef struct _SHUTDOWN_DLG_CONTEXTPSHUTDOWN_DLG_CONTEXT
 

Functions

static BOOL GetShutdownReasonUI (VOID)
 
DWORD GetDefaultShutdownSelState (VOID)
 
DWORD LoadShutdownSelState (VOID)
 
VOID SaveShutdownSelState (IN DWORD ShutdownCode)
 
DWORD GetDefaultShutdownOptions (VOID)
 
DWORD GetAllowedShutdownOptions (VOID)
 
static VOID UpdateShutdownDesc (IN HWND hDlg, IN PSHUTDOWN_DLG_CONTEXT pContext)
 
static VOID ShutdownOnInit (IN HWND hDlg, IN PSHUTDOWN_DLG_CONTEXT pContext)
 
static VOID ShutdownOnOk (IN HWND hDlg, IN PGINA_CONTEXT pgContext)
 
static INT_PTR CALLBACK ShutdownDialogProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
INT_PTR ShutdownDialog (IN HWND hwndDlg, IN DWORD ShutdownOptions, IN PGINA_CONTEXT pgContext)
 
DWORD WINAPI ShellShutdownDialog (HWND hParent, LPWSTR lpUsername, BOOL bHideLogoff)
 

Macro Definition Documentation

◆ WLX_SHUTDOWN_STATE_HIBERNATE

#define WLX_SHUTDOWN_STATE_HIBERNATE   0x40

Definition at line 21 of file shutdown.c.

◆ WLX_SHUTDOWN_STATE_LOGOFF

#define WLX_SHUTDOWN_STATE_LOGOFF   0x01

Definition at line 15 of file shutdown.c.

◆ WLX_SHUTDOWN_STATE_POWER_OFF

#define WLX_SHUTDOWN_STATE_POWER_OFF   0x02

Definition at line 16 of file shutdown.c.

◆ WLX_SHUTDOWN_STATE_REBOOT

#define WLX_SHUTDOWN_STATE_REBOOT   0x04

Definition at line 17 of file shutdown.c.

◆ WLX_SHUTDOWN_STATE_SLEEP

#define WLX_SHUTDOWN_STATE_SLEEP   0x10

Definition at line 19 of file shutdown.c.

Typedef Documentation

◆ PSHUTDOWN_DLG_CONTEXT

◆ SHUTDOWN_DLG_CONTEXT

Function Documentation

◆ GetAllowedShutdownOptions()

DWORD GetAllowedShutdownOptions ( VOID  )

Definition at line 227 of file shutdown.c.

228 {
229  DWORD Options = 0;
230 
231  // FIXME: Compute those options accordings to current user's rights!
233 
234  if (IsPwrSuspendAllowed())
236 
237  if (IsPwrHibernateAllowed())
239 
240  return Options;
241 }
#define WLX_SHUTDOWN_STATE_SLEEP
Definition: shutdown.c:19
BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
Definition: powrprof.c:488
#define WLX_SHUTDOWN_STATE_HIBERNATE
Definition: shutdown.c:21
enum OPTION_FLAGS Options
Definition: stats.c:44
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
#define WLX_SHUTDOWN_STATE_LOGOFF
Definition: shutdown.c:15
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17
BOOLEAN WINAPI IsPwrHibernateAllowed(VOID)
Definition: powrprof.c:450

Referenced by OnShutDown(), ShellShutdownDialog(), and ShutdownDialog().

◆ GetDefaultShutdownOptions()

DWORD GetDefaultShutdownOptions ( VOID  )

Definition at line 221 of file shutdown.c.

222 {
224 }
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17

Referenced by OnShutDown().

◆ GetDefaultShutdownSelState()

DWORD GetDefaultShutdownSelState ( VOID  )

Definition at line 95 of file shutdown.c.

96 {
98 }
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62

Referenced by OnShutDown().

◆ GetShutdownReasonUI()

static BOOL GetShutdownReasonUI ( VOID  )
static

Definition at line 36 of file shutdown.c.

37 {
38  OSVERSIONINFOEX VersionInfo;
39  DWORD dwValue, dwSize;
40  HKEY hKey;
41  LONG lRet;
42 
43  /* Query the policy value */
45  L"Software\\Policies\\Microsoft\\Windows NT\\Reliability",
46  0,
48  &hKey);
49  if (lRet == ERROR_SUCCESS)
50  {
51  dwValue = 0;
52  dwSize = sizeof(dwValue);
53  RegQueryValueExW(hKey,
54  L"ShutdownReasonUI",
55  NULL,
56  NULL,
57  (LPBYTE)&dwValue,
58  &dwSize);
59  RegCloseKey(hKey);
60 
61  return (dwValue != 0) ? TRUE : FALSE;
62  }
63 
64  /* Query the machine value */
66  L"Software\\Microsoft\\Windows\\CurrentVersion\\Reliability",
67  0,
69  &hKey);
70  if (lRet == ERROR_SUCCESS)
71  {
72  dwValue = 0;
73  dwSize = sizeof(dwValue);
74  RegQueryValueExW(hKey,
75  L"ShutdownReasonUI",
76  NULL,
77  NULL,
78  (LPBYTE)&dwValue,
79  &dwSize);
80  RegCloseKey(hKey);
81 
82  return (dwValue != 0) ? TRUE : FALSE;
83  }
84 
85  /* Return the default value */
86  VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
87  if (!GetVersionEx((POSVERSIONINFO)&VersionInfo))
88  return FALSE;
89 
90  return FALSE;
91 // return (VersionInfo.wProductType == VER_NT_WORKSTATION) ? FALSE : TRUE;
92 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:251
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define GetVersionEx
Definition: winbase.h:3692
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by ShutdownDialog().

◆ LoadShutdownSelState()

DWORD LoadShutdownSelState ( VOID  )

Definition at line 101 of file shutdown.c.

102 {
103  LONG lRet;
104  HKEY hKeyCurrentUser, hKey;
105  DWORD dwValue, dwTemp, dwSize;
106 
107  /* Default to shutdown */
109 
110  /* Open the current user HKCU key */
111  lRet = RegOpenCurrentUser(MAXIMUM_ALLOWED, &hKeyCurrentUser);
112  if (lRet == ERROR_SUCCESS)
113  {
114  /* Open the subkey */
115  lRet = RegOpenKeyExW(hKeyCurrentUser,
116  L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
117  0, KEY_QUERY_VALUE, &hKey);
118  RegCloseKey(hKeyCurrentUser);
119  }
120  if (lRet != ERROR_SUCCESS)
121  return dwValue;
122 
123  /* Read the value */
124  dwSize = sizeof(dwTemp);
125  lRet = RegQueryValueExW(hKey,
126  L"Shutdown Setting",
127  NULL, NULL,
128  (LPBYTE)&dwTemp, &dwSize);
129  RegCloseKey(hKey);
130 
131  if (lRet == ERROR_SUCCESS)
132  {
133  switch (dwTemp)
134  {
136  dwValue = WLX_SAS_ACTION_LOGOFF;
137  break;
138 
141  break;
142 
145  break;
146 
147  // 0x08
148 
151  break;
152 
153  // 0x20
154 
157  break;
158 
159  // 0x80
160  }
161  }
162 
163  return dwValue;
164 }
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define WLX_SHUTDOWN_STATE_SLEEP
Definition: shutdown.c:19
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WLX_SHUTDOWN_STATE_HIBERNATE
Definition: shutdown.c:21
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
long LONG
Definition: pedump.c:60
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
smooth NULL
Definition: ftsmooth.c:416
#define WLX_SHUTDOWN_STATE_LOGOFF
Definition: shutdown.c:15
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3232
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by OnShutDown(), ShellShutdownDialog(), and ShutdownDialog().

◆ SaveShutdownSelState()

VOID SaveShutdownSelState ( IN DWORD  ShutdownCode)

Definition at line 167 of file shutdown.c.

169 {
170  LONG lRet;
171  HKEY hKeyCurrentUser, hKey;
172  DWORD dwValue = 0;
173 
174  /* Open the current user HKCU key */
175  lRet = RegOpenCurrentUser(MAXIMUM_ALLOWED, &hKeyCurrentUser);
176  if (lRet == ERROR_SUCCESS)
177  {
178  /* Create the subkey */
179  lRet = RegCreateKeyExW(hKeyCurrentUser,
180  L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
181  0, NULL,
184  NULL, &hKey, NULL);
185  RegCloseKey(hKeyCurrentUser);
186  }
187  if (lRet != ERROR_SUCCESS)
188  return;
189 
190  switch (ShutdownCode)
191  {
193  dwValue = WLX_SHUTDOWN_STATE_LOGOFF;
194  break;
195 
198  break;
199 
201  dwValue = WLX_SHUTDOWN_STATE_REBOOT;
202  break;
203 
205  dwValue = WLX_SHUTDOWN_STATE_SLEEP;
206  break;
207 
210  break;
211  }
212 
213  RegSetValueExW(hKey,
214  L"Shutdown Setting",
215  0, REG_DWORD,
216  (LPBYTE)&dwValue, sizeof(dwValue));
217  RegCloseKey(hKey);
218 }
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define WLX_SHUTDOWN_STATE_SLEEP
Definition: shutdown.c:19
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define WLX_SHUTDOWN_STATE_HIBERNATE
Definition: shutdown.c:21
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
long LONG
Definition: pedump.c:60
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
#define WLX_SHUTDOWN_STATE_LOGOFF
Definition: shutdown.c:15
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3232
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by ShellShutdownDialog(), and ShutdownDialog().

◆ ShellShutdownDialog()

DWORD WINAPI ShellShutdownDialog ( HWND  hParent,
LPWSTR  lpUsername,
BOOL  bHideLogoff 
)

Definition at line 560 of file shutdown.c.

564 {
565  INT_PTR dlgValue;
566  DWORD ShutdownOptions;
567 
568  /*
569  * As we are called by the shell itself, don't use
570  * the cached GINA context but use a local copy here.
571  */
572  GINA_CONTEXT gContext = { 0 };
574 
575  UNREFERENCED_PARAMETER(lpUsername);
576 
577  ShutdownOptions = GetAllowedShutdownOptions();
578  if (bHideLogoff)
579  ShutdownOptions &= ~WLX_SHUTDOWN_STATE_LOGOFF;
580 
581  /* Initialize our local GINA context */
582  gContext.hDllInstance = hDllInstance;
583  BufferSize = _countof(gContext.UserName);
584  // NOTE: Only when this function is called, Win checks inside
585  // HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
586  // value "Logon User Name", and determines whether it will display
587  // the user name.
588  GetUserNameW(gContext.UserName, &BufferSize);
590 
591  /* Load the shutdown dialog box */
592  dlgValue = ShutdownDialog(hParent, ShutdownOptions, &gContext);
593 
594  /* Determine what to do based on user selection */
595  if (dlgValue == IDOK)
596  {
598 
599  switch (gContext.nShutdownAction)
600  {
603 
606 
609 
610  // 0x08
611 
614 
615  // 0x20
616 
619 
620  // 0x80
621  }
622  }
623  /* Help file is called directly here */
624  else if (dlgValue == IDHELP)
625  {
626  FIXME("Help is not implemented yet.");
627  MessageBoxW(hParent, L"Help is not implemented yet.", L"Message", MB_OK | MB_ICONEXCLAMATION);
628  }
629  else if (dlgValue == -1)
630  {
631  ERR("Failed to create dialog\n");
632  }
633 
634  return 0;
635 }
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define WLX_SHUTDOWN_STATE_SLEEP
Definition: shutdown.c:19
#define IDOK
Definition: winuser.h:824
DWORD LoadShutdownSelState(VOID)
Definition: shutdown.c:101
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define WLX_SHUTDOWN_STATE_HIBERNATE
Definition: shutdown.c:21
INT_PTR ShutdownDialog(IN HWND hwndDlg, IN DWORD ShutdownOptions, IN PGINA_CONTEXT pgContext)
Definition: shutdown.c:493
int32_t INT_PTR
Definition: typedefs.h:63
HANDLE hDllInstance
Definition: msgina.h:37
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
#define IDHELP
Definition: resource_2.h:8
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
ULONG nShutdownAction
Definition: msgina.h:47
#define FIXME(fmt,...)
Definition: debug.h:111
DWORD GetAllowedShutdownOptions(VOID)
Definition: shutdown.c:227
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
WCHAR UserName[256]
Definition: msgina.h:50
static HINSTANCE hDllInstance
Definition: clb.c:30
#define WLX_SHUTDOWN_STATE_LOGOFF
Definition: shutdown.c:15
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define _countof(array)
Definition: sndvol32.h:68
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define ERR(fmt,...)
Definition: debug.h:110
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17
#define MB_OK
Definition: winuser.h:784
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
VOID SaveShutdownSelState(IN DWORD ShutdownCode)
Definition: shutdown.c:167

◆ ShutdownDialog()

INT_PTR ShutdownDialog ( IN HWND  hwndDlg,
IN DWORD  ShutdownOptions,
IN PGINA_CONTEXT  pgContext 
)

Definition at line 493 of file shutdown.c.

497 {
498  INT_PTR ret;
500 
501 #if 0
502  DWORD ShutdownOptions;
503 
504  // FIXME: User impersonation!!
505  pgContext->nShutdownAction = LoadShutdownSelState();
506  ShutdownOptions = GetAllowedShutdownOptions();
507 #endif
508 
509  Context.pgContext = pgContext;
510  Context.ShutdownOptions = ShutdownOptions;
511  Context.bCloseDlg = FALSE;
512  Context.bReasonUI = GetShutdownReasonUI();
513 
514  if (pgContext->hWlx && pgContext->pWlxFuncs)
515  {
516  ret = pgContext->pWlxFuncs->WlxDialogBoxParam(pgContext->hWlx,
517  pgContext->hDllInstance,
519  hwndDlg,
521  (LPARAM)&Context);
522  }
523  else
524  {
525  ret = DialogBoxParamW(pgContext->hDllInstance,
527  hwndDlg,
529  (LPARAM)&Context);
530  }
531 
532 #if 0
533  // FIXME: User impersonation!!
534  if (ret == IDOK)
535  SaveShutdownSelState(pgContext->nShutdownAction);
536 #endif
537 
538  return ret;
539 }
#define IDD_SHUTDOWN
Definition: resource.h:43
#define IDOK
Definition: winuser.h:824
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
DWORD LoadShutdownSelState(VOID)
Definition: shutdown.c:101
static INT_PTR CALLBACK ShutdownDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: shutdown.c:403
int32_t INT_PTR
Definition: typedefs.h:63
DWORD GetAllowedShutdownOptions(VOID)
Definition: shutdown.c:227
LONG_PTR LPARAM
Definition: windef.h:208
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static BOOL GetShutdownReasonUI(VOID)
Definition: shutdown.c:36
#define IDD_SHUTDOWN_REASON
Definition: resource.h:45
struct tagContext Context
Definition: acpixf.h:1034
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
VOID SaveShutdownSelState(IN DWORD ShutdownCode)
Definition: shutdown.c:167

Referenced by OnShutDown(), and ShellShutdownDialog().

◆ ShutdownDialogProc()

static INT_PTR CALLBACK ShutdownDialogProc ( HWND  hDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 403 of file shutdown.c.

408 {
409  PSHUTDOWN_DLG_CONTEXT pContext;
410 
412 
413  switch (uMsg)
414  {
415  case WM_INITDIALOG:
416  {
417  pContext = (PSHUTDOWN_DLG_CONTEXT)lParam;
418  SetWindowLongPtrW(hDlg, GWLP_USERDATA, (LONG_PTR)pContext);
419 
420  ShutdownOnInit(hDlg, pContext);
421 
422  /* Draw the logo bitmap */
423  pContext->hBitmap =
425  return TRUE;
426  }
427 
428  case WM_DESTROY:
429  DeleteObject(pContext->hBitmap);
430  return TRUE;
431 
432  case WM_ACTIVATE:
433  {
434  /*
435  * If the user deactivates the shutdown dialog (it loses its focus
436  * while the dialog is not being closed), then destroy the dialog
437  * and cancel shutdown.
438  */
439  if (LOWORD(wParam) == WA_INACTIVE)
440  {
441  if (!pContext->bCloseDlg)
442  {
443  pContext->bCloseDlg = TRUE;
444  EndDialog(hDlg, 0);
445  }
446  }
447  return FALSE;
448  }
449 
450  case WM_PAINT:
451  {
452  PAINTSTRUCT ps;
453  if (pContext->hBitmap)
454  {
455  BeginPaint(hDlg, &ps);
456  DrawStateW(ps.hdc, NULL, NULL, (LPARAM)pContext->hBitmap, (WPARAM)0, 0, 0, 0, 0, DST_BITMAP);
457  EndPaint(hDlg, &ps);
458  }
459  return TRUE;
460  }
461 
462  case WM_CLOSE:
463  pContext->bCloseDlg = TRUE;
464  EndDialog(hDlg, IDCANCEL);
465  break;
466 
467  case WM_COMMAND:
468  switch (LOWORD(wParam))
469  {
470  case IDOK:
471  ShutdownOnOk(hDlg, pContext->pgContext);
472 
473  /* Fall back */
474  case IDCANCEL:
475  case IDHELP:
476  pContext->bCloseDlg = TRUE;
477  EndDialog(hDlg, LOWORD(wParam));
478  break;
479 
480  case IDC_SHUTDOWN_ACTION:
481  UpdateShutdownDesc(hDlg, pContext);
482  break;
483  }
484  break;
485 
486  default:
487  return FALSE;
488  }
489  return TRUE;
490 }
#define IDI_ROSLOGO
Definition: resource.h:42
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
static VOID ShutdownOnInit(IN HWND hDlg, IN PSHUTDOWN_DLG_CONTEXT pContext)
Definition: shutdown.c:296
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowLongPtrW
Definition: winuser.h:4804
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HANDLE hDllInstance
Definition: msgina.h:37
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define IDHELP
Definition: resource_2.h:8
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define GWLP_USERDATA
Definition: treelist.c:63
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
struct _SHUTDOWN_DLG_CONTEXT * PSHUTDOWN_DLG_CONTEXT
PGINA_CONTEXT pgContext
Definition: shutdown.c:26
#define WM_DESTROY
Definition: winuser.h:1591
#define IDC_SHUTDOWN_ACTION
Definition: resource.h:47
#define WM_CLOSE
Definition: winuser.h:1603
#define WM_PAINT
Definition: winuser.h:1602
BOOL WINAPI DrawStateW(_In_ HDC, _In_opt_ HBRUSH, _In_opt_ DRAWSTATEPROC, _In_ LPARAM, _In_ WPARAM, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_COMMAND
Definition: winuser.h:1722
#define WM_ACTIVATE
Definition: winuser.h:1594
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define IMAGE_BITMAP
Definition: winuser.h:211
#define DST_BITMAP
Definition: winuser.h:516
static VOID ShutdownOnOk(IN HWND hDlg, IN PGINA_CONTEXT pgContext)
Definition: shutdown.c:379
#define SetWindowLongPtrW
Definition: winuser.h:5321
#define WA_INACTIVE
Definition: winuser.h:2597
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
static VOID UpdateShutdownDesc(IN HWND hDlg, IN PSHUTDOWN_DLG_CONTEXT pContext)
Definition: shutdown.c:244

Referenced by ShutdownDialog().

◆ ShutdownOnInit()

static VOID ShutdownOnInit ( IN HWND  hDlg,
IN PSHUTDOWN_DLG_CONTEXT  pContext 
)
static

Definition at line 296 of file shutdown.c.

299 {
300  PGINA_CONTEXT pgContext = pContext->pgContext;
301  HWND hwndList;
302  INT idx, count, i;
303  WCHAR szBuffer[256];
304  WCHAR szBuffer2[256];
305 
306  hwndList = GetDlgItem(hDlg, IDC_SHUTDOWN_ACTION);
307 
308  /* Clear the content before it's used */
309  SendMessageW(hwndList, CB_RESETCONTENT, 0, 0);
310 
311  /* Log off */
312  if (pContext->ShutdownOptions & WLX_SHUTDOWN_STATE_LOGOFF)
313  {
314  LoadStringW(pgContext->hDllInstance, IDS_SHUTDOWN_LOGOFF, szBuffer, _countof(szBuffer));
315  StringCchPrintfW(szBuffer2, _countof(szBuffer2), szBuffer, pgContext->UserName);
316  idx = SendMessageW(hwndList, CB_ADDSTRING, 0, (LPARAM)szBuffer2);
317  if (idx != CB_ERR)
319  }
320 
321  /* Shut down - DEFAULT */
322  if (pContext->ShutdownOptions & WLX_SHUTDOWN_STATE_POWER_OFF)
323  {
324  LoadStringW(pgContext->hDllInstance, IDS_SHUTDOWN_SHUTDOWN, szBuffer, _countof(szBuffer));
325  idx = SendMessageW(hwndList, CB_ADDSTRING, 0, (LPARAM)szBuffer);
326  if (idx != CB_ERR)
328  }
329 
330  /* Restart */
331  if (pContext->ShutdownOptions & WLX_SHUTDOWN_STATE_REBOOT)
332  {
333  LoadStringW(pgContext->hDllInstance, IDS_SHUTDOWN_RESTART, szBuffer, _countof(szBuffer));
334  idx = SendMessageW(hwndList, CB_ADDSTRING, 0, (LPARAM)szBuffer);
335  if (idx != CB_ERR)
337  }
338 
339  // if (pContext->ShutdownOptions & 0x08) {}
340 
341  /* Sleep */
342  if (pContext->ShutdownOptions & WLX_SHUTDOWN_STATE_SLEEP)
343  {
344  LoadStringW(pgContext->hDllInstance, IDS_SHUTDOWN_SLEEP, szBuffer, _countof(szBuffer));
345  idx = SendMessageW(hwndList, CB_ADDSTRING, 0, (LPARAM)szBuffer);
346  if (idx != CB_ERR)
348  }
349 
350  // if (pContext->ShutdownOptions & 0x20) {}
351 
352  /* Hibernate */
353  if (pContext->ShutdownOptions & WLX_SHUTDOWN_STATE_HIBERNATE)
354  {
355  LoadStringW(pgContext->hDllInstance, IDS_SHUTDOWN_HIBERNATE, szBuffer, _countof(szBuffer));
356  idx = SendMessageW(hwndList, CB_ADDSTRING, 0, (LPARAM)szBuffer);
357  if (idx != CB_ERR)
359  }
360 
361  // if (pContext->ShutdownOptions & 0x80) {}
362 
363  /* Set the default shut down selection */
364  count = SendMessageW(hwndList, CB_GETCOUNT, 0, 0);
365  for (i = 0; i < count; i++)
366  {
367  if (SendMessageW(hwndList, CB_GETITEMDATA, i, 0) == pgContext->nShutdownAction)
368  {
369  SendMessageW(hwndList, CB_SETCURSEL, i, 0);
370  break;
371  }
372  }
373 
374  /* Update the choice description based on the current selection */
375  UpdateShutdownDesc(hDlg, pContext);
376 }
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define CB_SETITEMDATA
Definition: winuser.h:1948
#define WLX_SHUTDOWN_STATE_SLEEP
Definition: shutdown.c:19
#define CB_GETITEMDATA
Definition: winuser.h:1932
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WLX_SHUTDOWN_STATE_HIBERNATE
Definition: shutdown.c:21
HANDLE hDllInstance
Definition: msgina.h:37
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:57
#define WLX_SHUTDOWN_STATE_POWER_OFF
Definition: shutdown.c:16
ULONG nShutdownAction
Definition: msgina.h:47
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
#define IDS_SHUTDOWN_RESTART
Definition: resource.h:99
unsigned int idx
Definition: utils.c:41
#define CB_ADDSTRING
Definition: winuser.h:1918
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
#define IDS_SHUTDOWN_SHUTDOWN
Definition: resource.h:97
LONG_PTR LPARAM
Definition: windef.h:208
WCHAR UserName[256]
Definition: msgina.h:50
#define CB_RESETCONTENT
Definition: winuser.h:1941
#define CB_ERR
Definition: winuser.h:2410
#define IDC_SHUTDOWN_ACTION
Definition: resource.h:47
#define WLX_SHUTDOWN_STATE_LOGOFF
Definition: shutdown.c:15
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define IDS_SHUTDOWN_LOGOFF
Definition: resource.h:98
#define IDS_SHUTDOWN_HIBERNATE
Definition: resource.h:101
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define CB_SETCURSEL
Definition: winuser.h:1943
#define IDS_SHUTDOWN_SLEEP
Definition: resource.h:100
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
#define WLX_SHUTDOWN_STATE_REBOOT
Definition: shutdown.c:17
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
#define CB_GETCOUNT
Definition: winuser.h:1924
static VOID UpdateShutdownDesc(IN HWND hDlg, IN PSHUTDOWN_DLG_CONTEXT pContext)
Definition: shutdown.c:244

Referenced by ShutdownDialogProc().

◆ ShutdownOnOk()

static VOID ShutdownOnOk ( IN HWND  hDlg,
IN PGINA_CONTEXT  pgContext 
)
static

Definition at line 379 of file shutdown.c.

382 {
383  INT idx;
384 
385  idx = SendDlgItemMessageW(hDlg,
387  CB_GETCURSEL,
388  0,
389  0);
390  if (idx != CB_ERR)
391  {
392  pgContext->nShutdownAction =
393  SendDlgItemMessageW(hDlg,
396  idx,
397  0);
398  }
399 }
#define CB_GETITEMDATA
Definition: winuser.h:1932
int32_t INT
Definition: typedefs.h:57
#define CB_GETCURSEL
Definition: winuser.h:1925
unsigned int idx
Definition: utils.c:41
#define CB_ERR
Definition: winuser.h:2410
#define IDC_SHUTDOWN_ACTION
Definition: resource.h:47
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by ShutdownDialogProc().

◆ UpdateShutdownDesc()

static VOID UpdateShutdownDesc ( IN HWND  hDlg,
IN PSHUTDOWN_DLG_CONTEXT  pContext 
)
static

Definition at line 244 of file shutdown.c.

247 {
248  UINT DescId = 0;
249  DWORD ShutdownCode;
250  WCHAR szBuffer[256];
251 
252  ShutdownCode = SendDlgItemMessageW(hDlg, IDC_SHUTDOWN_ACTION, CB_GETCURSEL, 0, 0);
253  if (ShutdownCode == CB_ERR) // Invalid selection
254  return;
255 
256  ShutdownCode = SendDlgItemMessageW(hDlg, IDC_SHUTDOWN_ACTION, CB_GETITEMDATA, ShutdownCode, 0);
257 
258  switch (ShutdownCode)
259  {
261  DescId = IDS_SHUTDOWN_LOGOFF_DESC;
262  break;
263 
266  break;
267 
269  DescId = IDS_SHUTDOWN_RESTART_DESC;
270  break;
271 
273  DescId = IDS_SHUTDOWN_SLEEP_DESC;
274  break;
275 
278  break;
279 
280  default:
281  break;
282  }
283 
284  LoadStringW(pContext->pgContext->hDllInstance, DescId, szBuffer, _countof(szBuffer));
285  SetDlgItemTextW(hDlg, IDC_SHUTDOWN_DESCRIPTION, szBuffer);
286 
287  if (pContext->bReasonUI)
288  {
292  }
293 }
#define WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
Definition: winwlx.h:66
#define IDS_SHUTDOWN_RESTART_DESC
Definition: resource.h:105
#define CB_GETITEMDATA
Definition: winuser.h:1932
#define IDS_SHUTDOWN_LOGOFF_DESC
Definition: resource.h:104
#define IDC_SHUTDOWN_DESCRIPTION
Definition: resource.h:48
#define IDS_SHUTDOWN_SLEEP_DESC
Definition: resource.h:106
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define CB_GETCURSEL
Definition: winuser.h:1925
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
#define IDC_REASON_PLANNED
Definition: resource.h:49
#define CB_ERR
Definition: winuser.h:2410
#define IDC_SHUTDOWN_ACTION
Definition: resource.h:47
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define IDC_REASON_COMMENT
Definition: resource.h:52
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define WLX_SAS_ACTION_SHUTDOWN_SLEEP
Definition: winwlx.h:64
unsigned int UINT
Definition: ndis.h:50
#define IDS_SHUTDOWN_HIBERNATE_DESC
Definition: resource.h:107
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
#define IDS_SHUTDOWN_SHUTDOWN_DESC
Definition: resource.h:103
#define IDC_REASON_LIST
Definition: resource.h:50

Referenced by ShutdownDialogProc(), and ShutdownOnInit().