2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS msgina.dll
4 * FILE: lib/msgina/shutdown.c
5 * PURPOSE: Shutdown Dialog Box
6 * PROGRAMMER: Lee Schroeder (spaceseel at gmail dot com)
15 int g_shutdownCode
= 0;
16 BOOL g_logoffHideState
= FALSE
;
18 VOID
UpdateShutdownShellDesc(HWND hwnd
)
21 UINT shutdownDescId
= 0;
22 HWND shutdownHwnd
= GetDlgItem(hwnd
, IDC_SHUTDOWN_DESCRIPTION
);
25 shutdownCode
= SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_GETCURSEL
, 0, 0);
27 if(!g_logoffHideState
)
32 shutdownDescId
= IDS_SHUTDOWN_LOGOFF_DESC
;
34 case 1: /* Shut down */
35 shutdownDescId
= IDS_SHUTDOWN_SHUTDOWN_DESC
;
38 shutdownDescId
= IDS_SHUTDOWN_RESTART_DESC
;
44 if (IsPwrSuspendAllowed())
46 if (shutdownCode
== 3) /* Sleep */
48 shutdownDescId
= IDS_SHUTDOWN_SLEEP_DESC
;
50 else if (shutdownCode
== 4) /* Hibernate */
52 shutdownDescId
= IDS_SHUTDOWN_HIBERNATE_DESC
;
57 if (shutdownCode
== 3) /* Hibernate */
59 shutdownDescId
= IDS_SHUTDOWN_SLEEP_DESC
;
67 case 0: /* Shut down */
68 shutdownDescId
= IDS_SHUTDOWN_SHUTDOWN_DESC
;
71 shutdownDescId
= IDS_SHUTDOWN_RESTART_DESC
;
77 if (IsPwrSuspendAllowed())
79 if (shutdownCode
== 2) /* Sleep */
81 shutdownDescId
= IDS_SHUTDOWN_SLEEP_DESC
;
83 else if (shutdownCode
== 3) /* Hibernate */
85 shutdownDescId
= IDS_SHUTDOWN_HIBERNATE_DESC
;
90 if (shutdownCode
== 2) /* Hibernate */
92 shutdownDescId
= IDS_SHUTDOWN_SLEEP_DESC
;
97 LoadStringW(hDllInstance
, shutdownDescId
, tmpBuffer
, sizeof(tmpBuffer
));
98 SetWindowTextW(shutdownHwnd
, tmpBuffer
);
101 BOOL CALLBACK
ExitWindowsDialogShellProc(HWND hwnd
, UINT Message
, WPARAM wParam
, LPARAM lParam
)
103 PGINA_CONTEXT pgContext
;
105 pgContext
= (PGINA_CONTEXT
)GetWindowLongPtr(hwnd
, GWL_USERDATA
);
112 WCHAR userBuffer
[256];
113 DWORD userBufferSize
= _countof(userBuffer
);
114 WCHAR tmpBuffer
[256];
115 WCHAR tmpBuffer2
[512];
117 pgContext
= (PGINA_CONTEXT
)lParam
;
120 WARN("pgContext is NULL, branding bitmaps will not be displayed.\n");
123 SetWindowLongPtr(hwnd
, GWL_USERDATA
, (DWORD_PTR
)pgContext
);
125 /* Clears the content before it's used */
126 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_RESETCONTENT
, 0, 0);
128 if(!g_logoffHideState
)
131 LoadStringW(hDllInstance
, IDS_SHUTDOWN_LOGOFF
, tmpBuffer
, sizeof(tmpBuffer
)/sizeof(WCHAR
));
132 GetUserNameW(userBuffer
, &userBufferSize
);
133 StringCchPrintfW(tmpBuffer2
, 512, tmpBuffer
, userBuffer
);
134 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_ADDSTRING
, 0, (LPARAM
)tmpBuffer2
);
137 /* Shut down - DEFAULT */
138 LoadStringW(hDllInstance
, IDS_SHUTDOWN_SHUTDOWN
, tmpBuffer
, sizeof(tmpBuffer
)/sizeof(WCHAR
));
139 defSelect
= SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_ADDSTRING
, 0, (LPARAM
)tmpBuffer
);
142 LoadStringW(hDllInstance
, IDS_SHUTDOWN_RESTART
, tmpBuffer
, sizeof(tmpBuffer
)/sizeof(WCHAR
));
143 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_ADDSTRING
, 0, (LPARAM
)tmpBuffer
);
146 if (IsPwrSuspendAllowed())
148 LoadStringW(hDllInstance
, IDS_SHUTDOWN_SLEEP
, tmpBuffer
, sizeof(tmpBuffer
)/sizeof(WCHAR
));
149 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_ADDSTRING
, 0, (LPARAM
)tmpBuffer
);
153 if (IsPwrHibernateAllowed())
155 LoadStringW(hDllInstance
, IDS_SHUTDOWN_HIBERNATE
, tmpBuffer
, sizeof(tmpBuffer
)/sizeof(WCHAR
));
156 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_ADDSTRING
, 0, (LPARAM
)tmpBuffer
);
159 /* Sets the default shut down selection */
160 SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_SETCURSEL
, defSelect
, 0);
162 /* Updates the choice description based on the current selection */
163 UpdateShutdownShellDesc(hwnd
);
165 /* Draw the logo graphic */
167 pgContext
->hBitmap
= LoadImage(hDllInstance
, MAKEINTRESOURCE(IDI_ROSLOGO
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
175 if (pgContext
&& pgContext
->hBitmap
)
177 hdc
= BeginPaint(hwnd
, &ps
);
178 DrawStateW(hdc
, NULL
, NULL
, (LPARAM
)pgContext
->hBitmap
, (WPARAM
)0, 0, 0, 0, 0, DST_BITMAP
);
187 DeleteObject(pgContext
->hBitmap
);
191 switch(LOWORD(wParam
))
194 g_shutdownCode
= SendDlgItemMessageW(hwnd
, IDC_SHUTDOWN_LIST
, CB_GETCURSEL
, (WPARAM
)0, (LPARAM
)0);
195 EndDialog(hwnd
, IDOK
);
198 EndDialog(hwnd
, IDCANCEL
);
201 EndDialog(hwnd
, IDHELP
);
203 case IDC_SHUTDOWN_LIST
:
204 UpdateShutdownShellDesc(hwnd
);
216 * - Based upon observations on the ShellShutdownDialog() function, the function doesn't actually
217 * do anything except show a dialog box and returning a value based upon the value chosen. That
218 * means that any code that calls the function has to execute the chosen action (shut down,
220 * - When this function is called in Windows XP, it shows the classic dialog box regardless if
221 * SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType is enabled or not.
222 * - When the Help button is pushed, it sends the same return value as IDCANCEL (0x00), but
223 * at the same time, it calls the help file directly from the dialog box.
224 * - When the dialog is created, it doesn't disable all other input from the other windows.
225 * This is done elsewhere. When running the function ShellShutdownDialog() from XP/2K3, if the user clicks
226 * out of the window, it automatically closes itself.
227 * - The parameter, lpUsername never seems to be used when calling the function from Windows XP. Either
228 * it was a parameter that was never used in the final version before release, or it has a use that
229 * is currently not known.
237 GINA_CONTEXT pgContext
= { 0 };
240 g_logoffHideState
= bHideLogoff
;
242 UNREFERENCED_PARAMETER(lpUsername
);
244 // Loads the shut down dialog box
245 dlgValue
= DialogBoxParam(hDllInstance
,
246 MAKEINTRESOURCE(IDD_SHUTDOWN_SHELL
),
248 ExitWindowsDialogShellProc
,
251 // Determines what to do based on user selection
252 if (dlgValue
== IDOK
)
254 switch (g_shutdownCode
)
256 case 0: /* Log off */
258 case 1: /* Shut down */
264 case 4: /* Hibernate */
268 /* Help file is called directly here */
269 else if (dlgValue
== IDHELP
)
271 FIXME("Help is not implemented yet.");
272 MessageBoxW(hParent
, L
"Help is not implemented yet.", L
"Message", MB_OK
| MB_ICONEXCLAMATION
);
274 else if (dlgValue
== -1)
276 ERR("Failed to create dialog\n");