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
28 LPCWSTR lpstrDirectory
;
30 LPCWSTR lpstrDescription
;
34 typedef BOOL (WINAPI
* LPFNOFN
) (OPENFILENAMEW
*) ;
36 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
37 static INT_PTR CALLBACK
RunDlgProc (HWND
, UINT
, WPARAM
, LPARAM
) ;
38 static void FillList (HWND
, char *, BOOL
) ;
41 /*************************************************************************
42 * PickIconDlg [SHELL32.62]
50 WCHAR szName
[MAX_PATH
];
52 }PICK_ICON_CONTEXT
, *PPICK_ICON_CONTEXT
;
54 BOOL CALLBACK
EnumPickIconResourceProc(HMODULE hModule
,
63 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
65 if (IS_INTRESOURCE(lpszName
))
66 swprintf(szName
, L
"%u", lpszName
);
68 wcscpy(szName
, (WCHAR
*)lpszName
);
71 hIcon
= LoadIconW(pIconContext
->hLibrary
, (LPCWSTR
)lpszName
);
75 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_ADDSTRING
, 0, (LPARAM
)szName
);
77 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETITEMDATA
, index
, (LPARAM
)hIcon
);
83 DestroyIconList(HWND hDlgCtrl
)
88 count
= SendMessage(hDlgCtrl
, LB_GETCOUNT
, 0, 0);
92 for(index
= 0; index
< count
; index
++)
94 HICON hIcon
= (HICON
)SendMessageW(hDlgCtrl
, LB_GETITEMDATA
, index
, 0);
99 INT_PTR CALLBACK
PickIconProc(HWND hwndDlg
,
105 LPMEASUREITEMSTRUCT lpmis
;
106 LPDRAWITEMSTRUCT lpdis
;
109 WCHAR szText
[MAX_PATH
], szTitle
[100], szFilter
[100];
110 OPENFILENAMEW ofn
= {0};
112 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
117 pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
118 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG
)pIconContext
);
119 pIconContext
->hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_PICKICON_LIST
);
120 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
121 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
122 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)szText
);
124 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)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 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)pIconContext
->szName
);
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 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)szText
);
184 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)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_DIALOG
), 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
,
276 static const WCHAR resnameW
[] = {'S','H','E','L','L','_','R','U','N','_','D','L','G',0};
277 RUNFILEDLGPARAMS rfdp
;
282 rfdp
.hwndOwner
= hwndOwner
;
284 rfdp
.lpstrDirectory
= lpstrDirectory
;
285 rfdp
.lpstrTitle
= lpstrTitle
;
286 rfdp
.lpstrDescription
= lpstrDescription
;
287 rfdp
.uFlags
= uFlags
;
289 if (!(hRes
= FindResourceW(shell32_hInstance
, resnameW
, (LPWSTR
)RT_DIALOG
)) ||
290 !(tmplate
= LoadResource(shell32_hInstance
, hRes
)))
292 ERR("Couldn't load SHELL_RUN_DLG resource\n");
293 ShellMessageBoxW(shell32_hInstance
, hwndOwner
, MAKEINTRESOURCEW(IDS_RUNDLG_ERROR
), NULL
, MB_OK
| MB_ICONERROR
);
297 DialogBoxIndirectParamW(shell32_hInstance
,
298 (LPCDLGTEMPLATEW
)tmplate
, hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
303 /* find the directory that contains the file being run */
304 static LPWSTR
RunDlg_GetParentDir(LPCWSTR cmdline
)
307 WCHAR
*dest
, *result
, *result_end
=NULL
;
308 static const WCHAR dotexeW
[] = {'.','e','x','e',0};
310 result
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(strlenW(cmdline
)+5));
314 TRACE("HeapAlloc couldn't allocate %d bytes\n", sizeof(WCHAR
)*(strlenW(cmdline
)+5));
324 while (*src
&& *src
!= '"')
337 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
339 strcatW(dest
, dotexeW
);
340 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
343 else if (*src
== '\\')
356 HeapFree(GetProcessHeap(), 0, result
);
362 /* Dialog procedure for RunFileDlg */
363 static INT_PTR CALLBACK
RunDlgProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
365 RUNFILEDLGPARAMS
*prfdp
= (RUNFILEDLGPARAMS
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
370 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
371 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LONG_PTR
)prfdp
);
373 if (prfdp
->lpstrTitle
)
374 SetWindowTextW(hwnd
, prfdp
->lpstrTitle
);
375 if (prfdp
->lpstrDescription
)
376 SetWindowTextW(GetDlgItem(hwnd
, IDC_RUNDLG_DESCRIPTION
), prfdp
->lpstrDescription
);
377 if (prfdp
->uFlags
& RFF_NOBROWSE
)
379 HWND browse
= GetDlgItem(hwnd
, IDC_RUNDLG_BROWSE
);
380 ShowWindow(browse
, SW_HIDE
);
381 EnableWindow(browse
, FALSE
);
383 if (prfdp
->uFlags
& RFF_NOLABEL
)
384 ShowWindow(GetDlgItem(hwnd
, IDC_RUNDLG_LABEL
), SW_HIDE
);
385 if (prfdp
->uFlags
& RFF_CALCDIRECTORY
)
386 FIXME("RFF_CALCDIRECTORY not supported\n");
388 if (prfdp
->hIcon
== NULL
)
389 prfdp
->hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
390 SendMessageW(hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)prfdp
->hIcon
);
391 SendMessageW(hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)prfdp
->hIcon
);
392 SendMessageW(GetDlgItem(hwnd
, IDC_RUNDLG_ICON
), STM_SETICON
, (WPARAM
)prfdp
->hIcon
, 0);
394 FillList (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), NULL
, (prfdp
->uFlags
& RFF_NODEFAULT
) == 0) ;
395 SetFocus (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
)) ;
399 switch (LOWORD (wParam
))
404 HWND htxt
= GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
);
405 if ((ic
= GetWindowTextLengthW (htxt
)))
407 WCHAR
*psz
, *parent
=NULL
;
408 SHELLEXECUTEINFOW sei
;
410 ZeroMemory (&sei
, sizeof(sei
)) ;
411 sei
.cbSize
= sizeof(sei
) ;
412 psz
= (WCHAR
*)HeapAlloc( GetProcessHeap(), 0, (ic
+ 1)*sizeof(WCHAR
) );
416 GetWindowTextW (htxt
, psz
, ic
+ 1) ;
418 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
419 * WM_NOTIFY before execution */
422 sei
.nShow
= SW_SHOWNORMAL
;
425 if (prfdp
->lpstrDirectory
)
426 sei
.lpDirectory
= prfdp
->lpstrDirectory
;
428 sei
.lpDirectory
= parent
= RunDlg_GetParentDir(sei
.lpFile
);
430 if (!ShellExecuteExW( &sei
))
432 HeapFree(GetProcessHeap(), 0, psz
);
433 HeapFree(GetProcessHeap(), 0, parent
);
434 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
438 /* FillList is still ANSI */
439 GetWindowTextA (htxt
, (LPSTR
)psz
, ic
+ 1) ;
440 FillList (htxt
, (LPSTR
)psz
, FALSE
) ;
442 HeapFree(GetProcessHeap(), 0, psz
);
443 HeapFree(GetProcessHeap(), 0, parent
);
450 EndDialog (hwnd
, 0) ;
453 case IDC_RUNDLG_BROWSE
:
455 HMODULE hComdlg
= NULL
;
456 LPFNOFN ofnProc
= NULL
;
457 static const WCHAR comdlg32W
[] = {'c','o','m','d','l','g','3','2',0};
458 WCHAR szFName
[1024] = {0};
459 WCHAR filter
[MAX_PATH
], szCaption
[MAX_PATH
];
462 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_FILTER
, filter
, MAX_PATH
);
463 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_CAPTION
, szCaption
, MAX_PATH
);
465 ZeroMemory(&ofn
, sizeof(ofn
));
466 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
467 ofn
.hwndOwner
= hwnd
;
468 ofn
.lpstrFilter
= filter
;
469 ofn
.lpstrFile
= szFName
;
471 ofn
.lpstrTitle
= szCaption
;
472 ofn
.Flags
= OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
;
473 ofn
.lpstrInitialDir
= prfdp
->lpstrDirectory
;
475 if (NULL
== (hComdlg
= LoadLibraryExW (comdlg32W
, NULL
, 0)) ||
476 NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameW")))
478 ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg
, ofnProc
);
479 ShellMessageBoxW(shell32_hInstance
, hwnd
, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR
), NULL
, MB_OK
| MB_ICONERROR
);
485 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
486 SetWindowTextW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), szFName
) ;
487 SendMessageW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
488 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
491 FreeLibrary (hComdlg
) ;
501 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
502 /* fShowDefault ignored if pszLatest != NULL */
503 static void FillList (HWND hCb
, char *pszLatest
, BOOL fShowDefault
)
506 /* char szDbgMsg[256] = "" ; */
507 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
508 DWORD icList
= 0, icCmd
= 0 ;
511 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
513 if (ERROR_SUCCESS
!= RegCreateKeyExA (
514 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
515 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
516 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
518 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
522 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
526 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
527 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
);
531 TRACE("HeapAlloc failed to allocate %d bytes\n", icList
);
537 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
541 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
543 if (pszList
[Nix
] > cMax
)
544 cMax
= pszList
[Nix
] ;
546 szIndex
[0] = pszList
[Nix
] ;
548 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
549 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
551 pszCmd
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
553 pszCmd
= (char *)HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
554 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
555 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
557 if (NULL
!= pszLatest
)
559 if (!lstrcmpiA(pszCmd
, pszLatest
))
562 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
563 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
565 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
566 SetWindowTextA (hCb
, pszCmd
) ;
567 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
569 cMatch
= pszList
[Nix
] ;
570 memmove (&pszList
[1], pszList
, Nix
) ;
571 pszList
[0] = cMatch
;
576 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
579 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
580 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
582 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
583 if (!Nix
&& fShowDefault
)
585 SetWindowTextA (hCb
, pszCmd
) ;
586 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
592 sprintf (szDbgMsg, "Doing loop thing.\n") ;
593 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
595 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
596 SetWindowTextA (hCb
, pszLatest
) ;
597 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
599 cMatch
= pszList
[Nix
] ;
600 memmove (&pszList
[1], pszList
, Nix
) ;
601 pszList
[0] = cMatch
;
602 szIndex
[0] = cMatch
;
603 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
607 if (!cMatch
&& NULL
!= pszLatest
)
610 sprintf (szDbgMsg, "Simply inserting (increasing list).\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)) ;
619 pszList
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
621 pszList
= (char *)HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
625 memmove (&pszList
[1], pszList
, icList
- 1) ;
626 pszList
[0] = cMatch
;
627 szIndex
[0] = cMatch
;
628 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
632 TRACE("HeapAlloc or HeapReAlloc failed to allocate enough bytes\n");
636 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
638 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
639 HeapFree( GetProcessHeap(), 0, pszList
) ;
643 /*************************************************************************
644 * ConfirmDialog [internal]
646 * Put up a confirm box, return TRUE if the user confirmed
648 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
653 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
654 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
655 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
659 /*************************************************************************
660 * RestartDialogEx [SHELL32.730]
663 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
665 TRACE("(%p)\n", hWndOwner
);
667 /* FIXME: use lpwstrReason */
668 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
671 TOKEN_PRIVILEGES npr
;
673 /* enable the shutdown privilege for the current process */
674 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
676 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
677 npr
.PrivilegeCount
= 1;
678 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
679 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
682 ExitWindowsEx(EWX_REBOOT
, uReason
);
689 /*************************************************************************
690 * LogoffWindowsDialog [SHELL32.54]
693 EXTERN_C
int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
695 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
697 ExitWindowsEx(EWX_LOGOFF
, 0);
702 /*************************************************************************
703 * RestartDialog [SHELL32.59]
706 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
708 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
712 /*************************************************************************
713 * ExitWindowsDialog [SHELL32.60]
716 * exported by ordinal
718 void WINAPI
ExitWindowsDialog (HWND hWndOwner
)
720 TRACE("(%p)\n", hWndOwner
);
722 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
725 TOKEN_PRIVILEGES npr
;
727 /* enable shutdown privilege for current process */
728 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
730 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
731 npr
.PrivilegeCount
= 1;
732 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
733 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
736 ExitWindowsEx(EWX_SHUTDOWN
, 0);