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
);
349 static void EnableOkButtonFromEditContents(HWND hwnd
)
353 HWND Edit
= GetDlgItem(hwnd
, IDC_RUNDLG_EDITPATH
);
354 Length
= GetWindowTextLengthA(Edit
);
357 PWCHAR psz
= (PWCHAR
)HeapAlloc(GetProcessHeap(), 0, (Length
+ 1) * sizeof(WCHAR
));
360 GetWindowTextW(Edit
, psz
, Length
+ 1);
361 for (n
= 0; n
< Length
&& !Enable
; ++n
)
362 Enable
= psz
[n
] != ' ';
363 HeapFree(GetProcessHeap(), 0, psz
);
368 EnableWindow(GetDlgItem(hwnd
, IDOK
), Enable
);
371 /* Dialog procedure for RunFileDlg */
372 static INT_PTR CALLBACK
RunDlgProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
374 RUNFILEDLGPARAMS
*prfdp
= (RUNFILEDLGPARAMS
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
379 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
380 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LONG_PTR
)prfdp
);
382 if (prfdp
->lpstrTitle
)
383 SetWindowTextW(hwnd
, prfdp
->lpstrTitle
);
384 if (prfdp
->lpstrDescription
)
385 SetWindowTextW(GetDlgItem(hwnd
, IDC_RUNDLG_DESCRIPTION
), prfdp
->lpstrDescription
);
386 if (prfdp
->uFlags
& RFF_NOBROWSE
)
388 HWND browse
= GetDlgItem(hwnd
, IDC_RUNDLG_BROWSE
);
389 ShowWindow(browse
, SW_HIDE
);
390 EnableWindow(browse
, FALSE
);
392 if (prfdp
->uFlags
& RFF_NOLABEL
)
393 ShowWindow(GetDlgItem(hwnd
, IDC_RUNDLG_LABEL
), SW_HIDE
);
394 if (prfdp
->uFlags
& RFF_CALCDIRECTORY
)
395 FIXME("RFF_CALCDIRECTORY not supported\n");
397 if (prfdp
->hIcon
== NULL
)
398 prfdp
->hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
399 SendMessageW(hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)prfdp
->hIcon
);
400 SendMessageW(hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)prfdp
->hIcon
);
402 FillList (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), NULL
, (prfdp
->uFlags
& RFF_NODEFAULT
) == 0);
403 EnableOkButtonFromEditContents(hwnd
);
404 SetFocus (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
));
408 switch (LOWORD (wParam
))
413 HWND htxt
= GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
);
414 if ((ic
= GetWindowTextLengthW (htxt
)))
416 WCHAR
*psz
, *parent
= NULL
;
417 SHELLEXECUTEINFOW sei
;
419 ZeroMemory (&sei
, sizeof(sei
));
420 sei
.cbSize
= sizeof(sei
);
421 psz
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, (ic
+ 1)*sizeof(WCHAR
));
425 GetWindowTextW(htxt
, psz
, ic
+ 1);
427 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
428 * WM_NOTIFY before execution */
431 sei
.nShow
= SW_SHOWNORMAL
;
434 if (prfdp
->lpstrDirectory
)
435 sei
.lpDirectory
= prfdp
->lpstrDirectory
;
437 sei
.lpDirectory
= parent
= RunDlg_GetParentDir(sei
.lpFile
);
439 if (!ShellExecuteExW(&sei
))
441 HeapFree(GetProcessHeap(), 0, psz
);
442 HeapFree(GetProcessHeap(), 0, parent
);
443 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
447 /* FillList is still ANSI */
448 GetWindowTextA (htxt
, (LPSTR
)psz
, ic
+ 1);
449 FillList (htxt
, (LPSTR
)psz
, FALSE
);
451 HeapFree(GetProcessHeap(), 0, psz
);
452 HeapFree(GetProcessHeap(), 0, parent
);
462 case IDC_RUNDLG_BROWSE
:
464 HMODULE hComdlg
= NULL
;
465 LPFNOFN ofnProc
= NULL
;
466 static const WCHAR comdlg32W
[] = L
"comdlg32";
467 WCHAR szFName
[1024] = {0};
468 WCHAR filter
[MAX_PATH
], szCaption
[MAX_PATH
];
471 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_FILTER
, filter
, MAX_PATH
);
472 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_CAPTION
, szCaption
, MAX_PATH
);
474 ZeroMemory(&ofn
, sizeof(ofn
));
475 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
476 ofn
.hwndOwner
= hwnd
;
477 ofn
.lpstrFilter
= filter
;
478 ofn
.lpstrFile
= szFName
;
480 ofn
.lpstrTitle
= szCaption
;
481 ofn
.Flags
= OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
;
482 ofn
.lpstrInitialDir
= prfdp
->lpstrDirectory
;
484 if (NULL
== (hComdlg
= LoadLibraryExW (comdlg32W
, NULL
, 0)) ||
485 NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameW")))
487 ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg
, ofnProc
);
488 ShellMessageBoxW(shell32_hInstance
, hwnd
, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR
), NULL
, MB_OK
| MB_ICONERROR
);
494 SetFocus (GetDlgItem (hwnd
, IDOK
));
495 SetWindowTextW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), szFName
);
496 SendMessageW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
497 EnableOkButtonFromEditContents(hwnd
);
498 SetFocus (GetDlgItem (hwnd
, IDOK
));
501 FreeLibrary (hComdlg
);
505 case IDC_RUNDLG_EDITPATH
:
507 if (HIWORD(wParam
) == CBN_EDITCHANGE
)
509 EnableOkButtonFromEditContents(hwnd
);
519 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
520 /* fShowDefault ignored if pszLatest != NULL */
521 static void FillList(HWND hCb
, char *pszLatest
, BOOL fShowDefault
)
524 /* char szDbgMsg[256] = "" ; */
525 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
526 DWORD icList
= 0, icCmd
= 0 ;
529 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
531 if (ERROR_SUCCESS
!= RegCreateKeyExA (
532 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
533 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
534 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
536 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
540 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
544 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
545 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
);
549 TRACE("HeapAlloc failed to allocate %d bytes\n", icList
);
555 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
559 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
561 if (pszList
[Nix
] > cMax
)
562 cMax
= pszList
[Nix
] ;
564 szIndex
[0] = pszList
[Nix
] ;
566 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
567 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
569 pszCmd
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
571 pszCmd
= (char *)HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
572 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
573 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
575 if (NULL
!= pszLatest
)
577 if (!lstrcmpiA(pszCmd
, pszLatest
))
580 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
581 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
583 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
584 SetWindowTextA (hCb
, pszCmd
) ;
585 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
587 cMatch
= pszList
[Nix
] ;
588 memmove (&pszList
[1], pszList
, Nix
) ;
589 pszList
[0] = cMatch
;
594 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
597 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
598 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
600 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
601 if (!Nix
&& fShowDefault
)
603 SetWindowTextA (hCb
, pszCmd
) ;
604 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
610 sprintf (szDbgMsg, "Doing loop thing.\n") ;
611 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
613 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
614 SetWindowTextA (hCb
, pszLatest
) ;
615 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
617 cMatch
= pszList
[Nix
] ;
618 memmove (&pszList
[1], pszList
, Nix
) ;
619 pszList
[0] = cMatch
;
620 szIndex
[0] = cMatch
;
621 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
625 if (!cMatch
&& NULL
!= pszLatest
)
628 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
629 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
631 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
632 SetWindowTextA (hCb
, pszLatest
) ;
633 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
637 pszList
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
639 pszList
= (char *)HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
643 memmove (&pszList
[1], pszList
, icList
- 1) ;
644 pszList
[0] = cMatch
;
645 szIndex
[0] = cMatch
;
646 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
650 TRACE("HeapAlloc or HeapReAlloc failed to allocate enough bytes\n");
654 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
656 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
657 HeapFree( GetProcessHeap(), 0, pszList
) ;
661 /*************************************************************************
662 * ConfirmDialog [internal]
664 * Put up a confirm box, return TRUE if the user confirmed
666 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
671 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
672 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
673 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
677 /*************************************************************************
678 * RestartDialogEx [SHELL32.730]
681 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
683 TRACE("(%p)\n", hWndOwner
);
685 /* FIXME: use lpwstrReason */
686 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
689 TOKEN_PRIVILEGES npr
;
691 /* enable the shutdown privilege for the current process */
692 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
694 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
695 npr
.PrivilegeCount
= 1;
696 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
697 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
700 ExitWindowsEx(EWX_REBOOT
, uReason
);
707 /*************************************************************************
708 * LogoffWindowsDialog [SHELL32.54]
711 EXTERN_C
int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
713 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
714 ExitWindowsEx(EWX_LOGOFF
, 0);
720 /*************************************************************************
721 * RestartDialog [SHELL32.59]
724 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
726 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
729 /*************************************************************************
730 * Used to get the shutdown privilege
732 VOID
ExitWindows_GetShutdownPrivilege(VOID
)
735 TOKEN_PRIVILEGES npr
;
737 /* enable shut down privilege for current process */
738 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
740 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
742 npr
.PrivilegeCount
= 1;
743 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
744 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
750 /*************************************************************************
751 * ExitWindowsDialog_backup
754 * used as a backup solution to shutdown the OS in case msgina.dll somehow
757 VOID
ExitWindowsDialog_backup(HWND hWndOwner
)
759 TRACE("(%p)\n", hWndOwner
);
761 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
763 ExitWindows_GetShutdownPrivilege();
764 ExitWindowsEx(EWX_SHUTDOWN
, 0);
768 /*************************************************************************
769 * ExitWindowsDialog [SHELL32.60]
772 * exported by ordinal
776 * - Implement the ability to show either the Welcome Screen or the classic dialog boxes based upon the
777 * registry value: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType.
779 void WINAPI
ExitWindowsDialog(HWND hWndOwner
)
781 typedef DWORD (WINAPI
*ShellShFunc
)(HWND hParent
, WCHAR
*Username
, BOOL bHideLogoff
);
782 HINSTANCE msginaDll
= LoadLibraryA("msgina.dll");
784 TRACE("(%p)\n", hWndOwner
);
786 /* If the DLL cannot be found for any reason, then it simply uses a
787 dialog box to ask if the user wants to shut down the computer. */
790 TRACE("Unable to load msgina.dll.\n");
791 ExitWindowsDialog_backup(hWndOwner
);
795 ShellShFunc pShellShutdownDialog
= (ShellShFunc
) GetProcAddress(msginaDll
, "ShellShutdownDialog");
797 if(pShellShutdownDialog
)
799 /* Actually call the function */
800 DWORD returnValue
= pShellShutdownDialog(hWndOwner
, NULL
, FALSE
);
804 case 0x01: /* Log off user */
806 ExitWindowsEx(EWX_LOGOFF
, 0);
809 case 0x02: /* Shut down */
811 ExitWindows_GetShutdownPrivilege();
812 ExitWindowsEx(EWX_SHUTDOWN
, 0);
815 case 0x03: /* Install Updates/Shutdown (?) */
819 case 0x04: /* Reboot */
821 ExitWindows_GetShutdownPrivilege();
822 ExitWindowsEx(EWX_REBOOT
, 0);
825 case 0x10: /* Sleep */
827 if(IsPwrSuspendAllowed())
829 ExitWindows_GetShutdownPrivilege();
830 SetSuspendState(FALSE
, FALSE
, FALSE
);
834 case 0x40: /* Hibernate */
836 if(IsPwrHibernateAllowed())
838 ExitWindows_GetShutdownPrivilege();
839 SetSuspendState(TRUE
, FALSE
, TRUE
);
843 /* If the option is any other value */
850 /* If the function cannot be found, then revert to using the backup solution */
851 TRACE("Unable to find the 'ShellShutdownDialog' function");
852 FreeLibrary(msginaDll
);
853 ExitWindowsDialog_backup(hWndOwner
);