4 * Copyright 2000 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 LPCWSTR lpstrDirectory
;
29 LPCWSTR lpstrDescription
;
33 typedef BOOL (WINAPI
* LPFNOFN
) (OPENFILENAMEW
*) ;
35 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
36 static INT_PTR CALLBACK
RunDlgProc (HWND
, UINT
, WPARAM
, LPARAM
) ;
37 static void FillList (HWND
, char *, BOOL
) ;
40 /*************************************************************************
41 * PickIconDlg [SHELL32.62]
49 WCHAR szName
[MAX_PATH
];
51 } PICK_ICON_CONTEXT
, *PPICK_ICON_CONTEXT
;
53 BOOL CALLBACK
EnumPickIconResourceProc(HMODULE hModule
,
62 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
64 if (IS_INTRESOURCE(lpszName
))
65 swprintf(szName
, L
"%u", (DWORD
)lpszName
);
67 wcscpy(szName
, (WCHAR
*)lpszName
);
70 hIcon
= LoadIconW(pIconContext
->hLibrary
, (LPCWSTR
)lpszName
);
74 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_ADDSTRING
, 0, (LPARAM
)szName
);
76 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETITEMDATA
, index
, (LPARAM
)hIcon
);
82 DestroyIconList(HWND hDlgCtrl
)
87 count
= SendMessage(hDlgCtrl
, LB_GETCOUNT
, 0, 0);
91 for(index
= 0; index
< count
; index
++)
93 HICON hIcon
= (HICON
)SendMessageW(hDlgCtrl
, LB_GETITEMDATA
, index
, 0);
98 INT_PTR CALLBACK
PickIconProc(HWND hwndDlg
,
104 LPMEASUREITEMSTRUCT lpmis
;
105 LPDRAWITEMSTRUCT lpdis
;
108 WCHAR szText
[MAX_PATH
], szTitle
[100], szFilter
[100];
109 OPENFILENAMEW ofn
= {0};
111 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
116 pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
117 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG
)pIconContext
);
118 pIconContext
->hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_PICKICON_LIST
);
119 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCOLUMNWIDTH
, 32, 0);
120 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
121 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
122 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, szText
);
124 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
);
126 count
= SendMessage(pIconContext
->hDlgCtrl
, LB_GETCOUNT
, 0, 0);
129 if (count
> pIconContext
->Index
)
130 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, pIconContext
->Index
, 0);
132 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
136 switch(LOWORD(wParam
))
139 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
140 pIconContext
->Index
= index
;
141 GetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
, MAX_PATH
);
142 DestroyIconList(pIconContext
->hDlgCtrl
);
143 EndDialog(hwndDlg
, 1);
146 DestroyIconList(pIconContext
->hDlgCtrl
);
147 EndDialog(hwndDlg
, 0);
149 case IDC_PICKICON_LIST
:
150 if (HIWORD(wParam
) == LBN_SELCHANGE
)
151 InvalidateRect((HWND
)lParam
, NULL
, TRUE
); // FIXME USE UPDATE RECT
153 case IDC_BUTTON_PATH
:
157 ofn
.lStructSize
= sizeof(ofn
);
158 ofn
.hwndOwner
= hwndDlg
;
159 ofn
.lpstrFile
= szText
;
160 ofn
.nMaxFile
= MAX_PATH
;
161 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(WCHAR
));
162 ofn
.lpstrTitle
= szTitle
;
163 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_FILTER
, szFilter
, sizeof(szFilter
) / sizeof(WCHAR
));
164 ofn
.lpstrFilter
= szFilter
;
165 if (GetOpenFileNameW(&ofn
))
169 if (!wcsicmp(pIconContext
->szName
, szText
))
172 DestroyIconList(pIconContext
->hDlgCtrl
);
174 hLibrary
= LoadLibraryExW(szText
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
175 if (hLibrary
== NULL
)
177 FreeLibrary(pIconContext
->hLibrary
);
178 pIconContext
->hLibrary
= hLibrary
;
179 wcscpy(pIconContext
->szName
, szText
);
180 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
181 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
182 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, szText
);
184 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
);
186 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
192 lpmis
= (LPMEASUREITEMSTRUCT
) lParam
;
193 lpmis
->itemHeight
= 32;
194 lpmis
->itemWidth
= 64;
197 lpdis
= (LPDRAWITEMSTRUCT
) lParam
;
198 if (lpdis
->itemID
== (UINT
)-1)
202 switch (lpdis
->itemAction
)
206 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
207 hIcon
=(HICON
)SendMessage(lpdis
->hwndItem
, LB_GETITEMDATA
, lpdis
->itemID
, (LPARAM
) 0);
209 if (lpdis
->itemID
== (UINT
)index
)
212 hBrush
= CreateSolidBrush(RGB(0, 0, 255));
213 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
214 DeleteObject(hBrush
);
219 hBrush
= CreateSolidBrush(RGB(255, 255, 255));
220 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
221 DeleteObject(hBrush
);
223 DrawIconEx(lpdis
->hDC
, lpdis
->rcItem
.left
,lpdis
->rcItem
.top
, hIcon
,
237 BOOL WINAPI
PickIconDlg(
245 PICK_ICON_CONTEXT IconContext
;
247 hLibrary
= LoadLibraryExW(lpstrFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
248 IconContext
.hLibrary
= hLibrary
;
249 IconContext
.Index
= *lpdwIconIndex
;
250 wcscpy(IconContext
.szName
, lpstrFile
);
252 res
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_PICK_ICON
), hwndOwner
, PickIconProc
, (LPARAM
)&IconContext
);
255 wcscpy(lpstrFile
, IconContext
.szName
);
256 *lpdwIconIndex
= IconContext
.Index
;
259 FreeLibrary(hLibrary
);
263 /*************************************************************************
264 * RunFileDlg [internal]
266 * The Unicode function that is available as ordinal 61 on Windows NT/2000/XP/...
268 void WINAPI
RunFileDlg(
271 LPCWSTR lpstrDirectory
,
273 LPCWSTR lpstrDescription
,
278 RUNFILEDLGPARAMS rfdp
;
279 rfdp
.hwndOwner
= hwndOwner
;
281 rfdp
.lpstrDirectory
= lpstrDirectory
;
282 rfdp
.lpstrTitle
= lpstrTitle
;
283 rfdp
.lpstrDescription
= lpstrDescription
;
284 rfdp
.uFlags
= uFlags
;
286 DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_RUN
), hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
291 /* find the directory that contains the file being run */
292 static LPWSTR
RunDlg_GetParentDir(LPCWSTR cmdline
)
295 WCHAR
*dest
, *result
, *result_end
=NULL
;
296 static const WCHAR dotexeW
[] = L
".exe";
298 result
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(strlenW(cmdline
)+5));
302 TRACE("HeapAlloc couldn't allocate %d bytes\n", sizeof(WCHAR
)*(strlenW(cmdline
)+5));
312 while (*src
&& *src
!= '"')
325 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
327 strcatW(dest
, dotexeW
);
328 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
331 else if (*src
== '\\')
344 HeapFree(GetProcessHeap(), 0, result
);
350 /* Dialog procedure for RunFileDlg */
351 static INT_PTR CALLBACK
RunDlgProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
353 RUNFILEDLGPARAMS
*prfdp
= (RUNFILEDLGPARAMS
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
358 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
359 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LONG_PTR
)prfdp
);
361 if (prfdp
->lpstrTitle
)
362 SetWindowTextW(hwnd
, prfdp
->lpstrTitle
);
363 if (prfdp
->lpstrDescription
)
364 SetWindowTextW(GetDlgItem(hwnd
, IDC_RUNDLG_DESCRIPTION
), prfdp
->lpstrDescription
);
365 if (prfdp
->uFlags
& RFF_NOBROWSE
)
367 HWND browse
= GetDlgItem(hwnd
, IDC_RUNDLG_BROWSE
);
368 ShowWindow(browse
, SW_HIDE
);
369 EnableWindow(browse
, FALSE
);
371 if (prfdp
->uFlags
& RFF_NOLABEL
)
372 ShowWindow(GetDlgItem(hwnd
, IDC_RUNDLG_LABEL
), SW_HIDE
);
373 if (prfdp
->uFlags
& RFF_CALCDIRECTORY
)
374 FIXME("RFF_CALCDIRECTORY not supported\n");
376 if (prfdp
->hIcon
== NULL
)
377 prfdp
->hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
378 SendMessageW(hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)prfdp
->hIcon
);
379 SendMessageW(hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)prfdp
->hIcon
);
380 SendMessageW(GetDlgItem(hwnd
, IDC_RUNDLG_ICON
), STM_SETICON
, (WPARAM
)prfdp
->hIcon
, 0);
382 FillList (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), NULL
, (prfdp
->uFlags
& RFF_NODEFAULT
) == 0);
383 SetFocus (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
));
387 switch (LOWORD (wParam
))
392 HWND htxt
= GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
);
393 if ((ic
= GetWindowTextLengthW (htxt
)))
395 WCHAR
*psz
, *parent
= NULL
;
396 SHELLEXECUTEINFOW sei
;
398 ZeroMemory (&sei
, sizeof(sei
));
399 sei
.cbSize
= sizeof(sei
);
400 psz
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, (ic
+ 1)*sizeof(WCHAR
));
404 GetWindowTextW(htxt
, psz
, ic
+ 1);
406 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
407 * WM_NOTIFY before execution */
410 sei
.nShow
= SW_SHOWNORMAL
;
413 if (prfdp
->lpstrDirectory
)
414 sei
.lpDirectory
= prfdp
->lpstrDirectory
;
416 sei
.lpDirectory
= parent
= RunDlg_GetParentDir(sei
.lpFile
);
418 if (!ShellExecuteExW(&sei
))
420 HeapFree(GetProcessHeap(), 0, psz
);
421 HeapFree(GetProcessHeap(), 0, parent
);
422 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
426 /* FillList is still ANSI */
427 GetWindowTextA (htxt
, (LPSTR
)psz
, ic
+ 1);
428 FillList (htxt
, (LPSTR
)psz
, FALSE
);
430 HeapFree(GetProcessHeap(), 0, psz
);
431 HeapFree(GetProcessHeap(), 0, parent
);
441 case IDC_RUNDLG_BROWSE
:
443 HMODULE hComdlg
= NULL
;
444 LPFNOFN ofnProc
= NULL
;
445 static const WCHAR comdlg32W
[] = L
"comdlg32";
446 WCHAR szFName
[1024] = {0};
447 WCHAR filter
[MAX_PATH
], szCaption
[MAX_PATH
];
450 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_FILTER
, filter
, MAX_PATH
);
451 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_CAPTION
, szCaption
, MAX_PATH
);
453 ZeroMemory(&ofn
, sizeof(ofn
));
454 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
455 ofn
.hwndOwner
= hwnd
;
456 ofn
.lpstrFilter
= filter
;
457 ofn
.lpstrFile
= szFName
;
459 ofn
.lpstrTitle
= szCaption
;
460 ofn
.Flags
= OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
;
461 ofn
.lpstrInitialDir
= prfdp
->lpstrDirectory
;
463 if (NULL
== (hComdlg
= LoadLibraryExW (comdlg32W
, NULL
, 0)) ||
464 NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameW")))
466 ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg
, ofnProc
);
467 ShellMessageBoxW(shell32_hInstance
, hwnd
, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR
), NULL
, MB_OK
| MB_ICONERROR
);
473 SetFocus (GetDlgItem (hwnd
, IDOK
));
474 SetWindowTextW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), szFName
);
475 SendMessageW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
476 SetFocus (GetDlgItem (hwnd
, IDOK
));
479 FreeLibrary (hComdlg
);
489 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
490 /* fShowDefault ignored if pszLatest != NULL */
491 static void FillList(HWND hCb
, char *pszLatest
, BOOL fShowDefault
)
494 /* char szDbgMsg[256] = "" ; */
495 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
496 DWORD icList
= 0, icCmd
= 0 ;
499 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
501 if (ERROR_SUCCESS
!= RegCreateKeyExA (
502 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
503 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
504 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
506 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
510 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
514 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
515 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
);
519 TRACE("HeapAlloc failed to allocate %d bytes\n", icList
);
525 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
529 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
531 if (pszList
[Nix
] > cMax
)
532 cMax
= pszList
[Nix
] ;
534 szIndex
[0] = pszList
[Nix
] ;
536 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
537 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
539 pszCmd
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
541 pszCmd
= (char *)HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
542 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
543 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
545 if (NULL
!= pszLatest
)
547 if (!lstrcmpiA(pszCmd
, pszLatest
))
550 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
551 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
553 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
554 SetWindowTextA (hCb
, pszCmd
) ;
555 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
557 cMatch
= pszList
[Nix
] ;
558 memmove (&pszList
[1], pszList
, Nix
) ;
559 pszList
[0] = cMatch
;
564 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
567 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
568 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
570 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
571 if (!Nix
&& fShowDefault
)
573 SetWindowTextA (hCb
, pszCmd
) ;
574 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
580 sprintf (szDbgMsg, "Doing loop thing.\n") ;
581 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
583 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
584 SetWindowTextA (hCb
, pszLatest
) ;
585 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
587 cMatch
= pszList
[Nix
] ;
588 memmove (&pszList
[1], pszList
, Nix
) ;
589 pszList
[0] = cMatch
;
590 szIndex
[0] = cMatch
;
591 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
595 if (!cMatch
&& NULL
!= pszLatest
)
598 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
599 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
601 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
602 SetWindowTextA (hCb
, pszLatest
) ;
603 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
607 pszList
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
609 pszList
= (char *)HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
613 memmove (&pszList
[1], pszList
, icList
- 1) ;
614 pszList
[0] = cMatch
;
615 szIndex
[0] = cMatch
;
616 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
620 TRACE("HeapAlloc or HeapReAlloc failed to allocate enough bytes\n");
624 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
626 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
627 HeapFree( GetProcessHeap(), 0, pszList
) ;
631 /*************************************************************************
632 * ConfirmDialog [internal]
634 * Put up a confirm box, return TRUE if the user confirmed
636 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
641 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
642 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
643 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
647 /*************************************************************************
648 * RestartDialogEx [SHELL32.730]
651 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
653 TRACE("(%p)\n", hWndOwner
);
655 /* FIXME: use lpwstrReason */
656 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
659 TOKEN_PRIVILEGES npr
;
661 /* enable the shutdown privilege for the current process */
662 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
664 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
665 npr
.PrivilegeCount
= 1;
666 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
667 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
670 ExitWindowsEx(EWX_REBOOT
, uReason
);
677 /*************************************************************************
678 * LogoffWindowsDialog [SHELL32.54]
681 EXTERN_C
int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
683 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
684 ExitWindowsEx(EWX_LOGOFF
, 0);
690 /*************************************************************************
691 * RestartDialog [SHELL32.59]
694 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
696 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
699 /*************************************************************************
700 * Used to get the shutdown privilege
702 VOID
ExitWindows_GetShutdownPrivilege(VOID
)
705 TOKEN_PRIVILEGES npr
;
707 /* enable shut down privilege for current process */
708 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
710 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
712 npr
.PrivilegeCount
= 1;
713 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
714 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
720 /*************************************************************************
721 * ExitWindowsDialog_backup
724 * used as a backup solution to shutdown the OS in case msgina.dll somehow
727 VOID
ExitWindowsDialog_backup(HWND hWndOwner
)
729 TRACE("(%p)\n", hWndOwner
);
731 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
733 ExitWindows_GetShutdownPrivilege();
734 ExitWindowsEx(EWX_SHUTDOWN
, 0);
738 /*************************************************************************
739 * ExitWindowsDialog [SHELL32.60]
742 * exported by ordinal
746 * - Implement the ability to show either the Welcome Screen or the classic dialog boxes based upon the
747 * registry value: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType.
749 void WINAPI
ExitWindowsDialog(HWND hWndOwner
)
751 typedef DWORD (WINAPI
*ShellShFunc
)(HWND hParent
, WCHAR
*Username
, BOOL bHideLogoff
);
752 HINSTANCE msginaDll
= LoadLibraryA("msgina.dll");
754 TRACE("(%p)\n", hWndOwner
);
756 /* If the DLL cannot be found for any reason, then it simply uses a
757 dialog box to ask if the user wants to shut down the computer. */
760 TRACE("Unable to load msgina.dll.\n");
761 ExitWindowsDialog_backup(hWndOwner
);
765 ShellShFunc pShellShutdownDialog
= (ShellShFunc
) GetProcAddress(msginaDll
, "ShellShutdownDialog");
767 if(pShellShutdownDialog
)
769 /* Actually call the function */
770 DWORD returnValue
= pShellShutdownDialog(hWndOwner
, NULL
, FALSE
);
774 case 0x01: /* Log off user */
776 ExitWindowsEx(EWX_LOGOFF
, 0);
779 case 0x02: /* Shut down */
781 ExitWindows_GetShutdownPrivilege();
782 ExitWindowsEx(EWX_SHUTDOWN
, 0);
785 case 0x03: /* Install Updates/Shutdown (?) */
789 case 0x04: /* Reboot */
791 ExitWindows_GetShutdownPrivilege();
792 ExitWindowsEx(EWX_REBOOT
, 0);
795 case 0x10: /* Sleep */
797 if(IsPwrSuspendAllowed())
799 ExitWindows_GetShutdownPrivilege();
800 SetSuspendState(FALSE
, FALSE
, FALSE
);
804 case 0x40: /* Hibernate */
806 if(IsPwrHibernateAllowed())
808 ExitWindows_GetShutdownPrivilege();
809 SetSuspendState(TRUE
, FALSE
, TRUE
);
813 /* If the option is any other value */
820 /* If the function cannot be found, then revert to using the backup solution */
821 TRACE("Unable to find the 'ShellShutdownDialog' function");
822 FreeLibrary(msginaDll
);
823 ExitWindowsDialog_backup(hWndOwner
);