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", 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 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
120 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
121 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, szText
);
123 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
);
125 count
= SendMessage(pIconContext
->hDlgCtrl
, LB_GETCOUNT
, 0, 0);
128 if (count
> pIconContext
->Index
)
129 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, pIconContext
->Index
, 0);
131 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
135 switch(LOWORD(wParam
))
138 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
139 pIconContext
->Index
= index
;
140 GetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
, MAX_PATH
);
141 DestroyIconList(pIconContext
->hDlgCtrl
);
142 EndDialog(hwndDlg
, 1);
145 DestroyIconList(pIconContext
->hDlgCtrl
);
146 EndDialog(hwndDlg
, 0);
148 case IDC_PICKICON_LIST
:
149 if (HIWORD(wParam
) == LBN_SELCHANGE
)
150 InvalidateRect((HWND
)lParam
, NULL
, TRUE
); // FIXME USE UPDATE RECT
152 case IDC_BUTTON_PATH
:
156 ofn
.lStructSize
= sizeof(ofn
);
157 ofn
.hwndOwner
= hwndDlg
;
158 ofn
.lpstrFile
= szText
;
159 ofn
.nMaxFile
= MAX_PATH
;
160 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(WCHAR
));
161 ofn
.lpstrTitle
= szTitle
;
162 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_FILTER
, szFilter
, sizeof(szFilter
) / sizeof(WCHAR
));
163 ofn
.lpstrFilter
= szFilter
;
164 if (GetOpenFileNameW(&ofn
))
168 if (!wcsicmp(pIconContext
->szName
, szText
))
171 DestroyIconList(pIconContext
->hDlgCtrl
);
173 hLibrary
= LoadLibraryExW(szText
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
174 if (hLibrary
== NULL
)
176 FreeLibrary(pIconContext
->hLibrary
);
177 pIconContext
->hLibrary
= hLibrary
;
178 wcscpy(pIconContext
->szName
, szText
);
179 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
180 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
181 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, szText
);
183 SetDlgItemTextW(hwndDlg
, IDC_EDIT_PATH
, pIconContext
->szName
);
185 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
191 lpmis
= (LPMEASUREITEMSTRUCT
) lParam
;
192 lpmis
->itemHeight
= 32;
193 lpmis
->itemWidth
= 64;
196 lpdis
= (LPDRAWITEMSTRUCT
) lParam
;
197 if (lpdis
->itemID
== (UINT
)-1)
201 switch (lpdis
->itemAction
)
205 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
206 hIcon
=(HICON
)SendMessage(lpdis
->hwndItem
, LB_GETITEMDATA
, lpdis
->itemID
, (LPARAM
) 0);
208 if (lpdis
->itemID
== (UINT
)index
)
211 hBrush
= CreateSolidBrush(RGB(0, 0, 255));
212 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
213 DeleteObject(hBrush
);
218 hBrush
= CreateSolidBrush(RGB(255, 255, 255));
219 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
220 DeleteObject(hBrush
);
222 DrawIconEx(lpdis
->hDC
, lpdis
->rcItem
.left
,lpdis
->rcItem
.top
, hIcon
,
236 BOOL WINAPI
PickIconDlg(
244 PICK_ICON_CONTEXT IconContext
;
246 hLibrary
= LoadLibraryExW(lpstrFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
247 IconContext
.hLibrary
= hLibrary
;
248 IconContext
.Index
= *lpdwIconIndex
;
249 wcscpy(IconContext
.szName
, lpstrFile
);
251 res
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_PICK_ICON
), hwndOwner
, PickIconProc
, (LPARAM
)&IconContext
);
254 wcscpy(lpstrFile
, IconContext
.szName
);
255 *lpdwIconIndex
= IconContext
.Index
;
258 FreeLibrary(hLibrary
);
262 /*************************************************************************
263 * RunFileDlg [internal]
265 * The Unicode function that is available as ordinal 61 on Windows NT/2000/XP/...
267 void WINAPI
RunFileDlg(
270 LPCWSTR lpstrDirectory
,
272 LPCWSTR lpstrDescription
,
277 RUNFILEDLGPARAMS rfdp
;
278 rfdp
.hwndOwner
= hwndOwner
;
280 rfdp
.lpstrDirectory
= lpstrDirectory
;
281 rfdp
.lpstrTitle
= lpstrTitle
;
282 rfdp
.lpstrDescription
= lpstrDescription
;
283 rfdp
.uFlags
= uFlags
;
285 DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_RUN
), hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
290 /* find the directory that contains the file being run */
291 static LPWSTR
RunDlg_GetParentDir(LPCWSTR cmdline
)
294 WCHAR
*dest
, *result
, *result_end
=NULL
;
295 static const WCHAR dotexeW
[] = L
".exe";
297 result
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(strlenW(cmdline
)+5));
301 TRACE("HeapAlloc couldn't allocate %d bytes\n", sizeof(WCHAR
)*(strlenW(cmdline
)+5));
311 while (*src
&& *src
!= '"')
324 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
326 strcatW(dest
, dotexeW
);
327 if (INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(result
))
330 else if (*src
== '\\')
343 HeapFree(GetProcessHeap(), 0, result
);
349 /* Dialog procedure for RunFileDlg */
350 static INT_PTR CALLBACK
RunDlgProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
352 RUNFILEDLGPARAMS
*prfdp
= (RUNFILEDLGPARAMS
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
357 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
358 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LONG_PTR
)prfdp
);
360 if (prfdp
->lpstrTitle
)
361 SetWindowTextW(hwnd
, prfdp
->lpstrTitle
);
362 if (prfdp
->lpstrDescription
)
363 SetWindowTextW(GetDlgItem(hwnd
, IDC_RUNDLG_DESCRIPTION
), prfdp
->lpstrDescription
);
364 if (prfdp
->uFlags
& RFF_NOBROWSE
)
366 HWND browse
= GetDlgItem(hwnd
, IDC_RUNDLG_BROWSE
);
367 ShowWindow(browse
, SW_HIDE
);
368 EnableWindow(browse
, FALSE
);
370 if (prfdp
->uFlags
& RFF_NOLABEL
)
371 ShowWindow(GetDlgItem(hwnd
, IDC_RUNDLG_LABEL
), SW_HIDE
);
372 if (prfdp
->uFlags
& RFF_CALCDIRECTORY
)
373 FIXME("RFF_CALCDIRECTORY not supported\n");
375 if (prfdp
->hIcon
== NULL
)
376 prfdp
->hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
377 SendMessageW(hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)prfdp
->hIcon
);
378 SendMessageW(hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)prfdp
->hIcon
);
379 SendMessageW(GetDlgItem(hwnd
, IDC_RUNDLG_ICON
), STM_SETICON
, (WPARAM
)prfdp
->hIcon
, 0);
381 FillList (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), NULL
, (prfdp
->uFlags
& RFF_NODEFAULT
) == 0);
382 SetFocus (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
));
386 switch (LOWORD (wParam
))
391 HWND htxt
= GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
);
392 if ((ic
= GetWindowTextLengthW (htxt
)))
394 WCHAR
*psz
, *parent
= NULL
;
395 SHELLEXECUTEINFOW sei
;
397 ZeroMemory (&sei
, sizeof(sei
));
398 sei
.cbSize
= sizeof(sei
);
399 psz
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, (ic
+ 1)*sizeof(WCHAR
));
403 GetWindowTextW(htxt
, psz
, ic
+ 1);
405 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
406 * WM_NOTIFY before execution */
409 sei
.nShow
= SW_SHOWNORMAL
;
412 if (prfdp
->lpstrDirectory
)
413 sei
.lpDirectory
= prfdp
->lpstrDirectory
;
415 sei
.lpDirectory
= parent
= RunDlg_GetParentDir(sei
.lpFile
);
417 if (!ShellExecuteExW(&sei
))
419 HeapFree(GetProcessHeap(), 0, psz
);
420 HeapFree(GetProcessHeap(), 0, parent
);
421 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
425 /* FillList is still ANSI */
426 GetWindowTextA (htxt
, (LPSTR
)psz
, ic
+ 1);
427 FillList (htxt
, (LPSTR
)psz
, FALSE
);
429 HeapFree(GetProcessHeap(), 0, psz
);
430 HeapFree(GetProcessHeap(), 0, parent
);
440 case IDC_RUNDLG_BROWSE
:
442 HMODULE hComdlg
= NULL
;
443 LPFNOFN ofnProc
= NULL
;
444 static const WCHAR comdlg32W
[] = L
"comdlg32";
445 WCHAR szFName
[1024] = {0};
446 WCHAR filter
[MAX_PATH
], szCaption
[MAX_PATH
];
449 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_FILTER
, filter
, MAX_PATH
);
450 LoadStringW(shell32_hInstance
, IDS_RUNDLG_BROWSE_CAPTION
, szCaption
, MAX_PATH
);
452 ZeroMemory(&ofn
, sizeof(ofn
));
453 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
454 ofn
.hwndOwner
= hwnd
;
455 ofn
.lpstrFilter
= filter
;
456 ofn
.lpstrFile
= szFName
;
458 ofn
.lpstrTitle
= szCaption
;
459 ofn
.Flags
= OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
;
460 ofn
.lpstrInitialDir
= prfdp
->lpstrDirectory
;
462 if (NULL
== (hComdlg
= LoadLibraryExW (comdlg32W
, NULL
, 0)) ||
463 NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameW")))
465 ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg
, ofnProc
);
466 ShellMessageBoxW(shell32_hInstance
, hwnd
, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR
), NULL
, MB_OK
| MB_ICONERROR
);
472 SetFocus (GetDlgItem (hwnd
, IDOK
));
473 SetWindowTextW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), szFName
);
474 SendMessageW (GetDlgItem (hwnd
, IDC_RUNDLG_EDITPATH
), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1));
475 SetFocus (GetDlgItem (hwnd
, IDOK
));
478 FreeLibrary (hComdlg
);
488 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
489 /* fShowDefault ignored if pszLatest != NULL */
490 static void FillList(HWND hCb
, char *pszLatest
, BOOL fShowDefault
)
493 /* char szDbgMsg[256] = "" ; */
494 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
495 DWORD icList
= 0, icCmd
= 0 ;
498 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
500 if (ERROR_SUCCESS
!= RegCreateKeyExA (
501 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
502 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
503 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
505 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
509 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
513 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
514 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
);
518 TRACE("HeapAlloc failed to allocate %d bytes\n", icList
);
524 pszList
= (char *)HeapAlloc( GetProcessHeap(), 0, icList
) ;
528 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
530 if (pszList
[Nix
] > cMax
)
531 cMax
= pszList
[Nix
] ;
533 szIndex
[0] = pszList
[Nix
] ;
535 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
536 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
538 pszCmd
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
540 pszCmd
= (char *)HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
541 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
542 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
544 if (NULL
!= pszLatest
)
546 if (!lstrcmpiA(pszCmd
, pszLatest
))
549 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
550 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
552 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
553 SetWindowTextA (hCb
, pszCmd
) ;
554 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
556 cMatch
= pszList
[Nix
] ;
557 memmove (&pszList
[1], pszList
, Nix
) ;
558 pszList
[0] = cMatch
;
563 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
566 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
567 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
569 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
570 if (!Nix
&& fShowDefault
)
572 SetWindowTextA (hCb
, pszCmd
) ;
573 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
579 sprintf (szDbgMsg, "Doing loop thing.\n") ;
580 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
582 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
583 SetWindowTextA (hCb
, pszLatest
) ;
584 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
586 cMatch
= pszList
[Nix
] ;
587 memmove (&pszList
[1], pszList
, Nix
) ;
588 pszList
[0] = cMatch
;
589 szIndex
[0] = cMatch
;
590 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
594 if (!cMatch
&& NULL
!= pszLatest
)
597 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
598 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
600 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
601 SetWindowTextA (hCb
, pszLatest
) ;
602 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
606 pszList
= (char *)HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
608 pszList
= (char *)HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
612 memmove (&pszList
[1], pszList
, icList
- 1) ;
613 pszList
[0] = cMatch
;
614 szIndex
[0] = cMatch
;
615 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
619 TRACE("HeapAlloc or HeapReAlloc failed to allocate enough bytes\n");
623 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
625 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
626 HeapFree( GetProcessHeap(), 0, pszList
) ;
630 /*************************************************************************
631 * ConfirmDialog [internal]
633 * Put up a confirm box, return TRUE if the user confirmed
635 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
640 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
641 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
642 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
646 /*************************************************************************
647 * RestartDialogEx [SHELL32.730]
650 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
652 TRACE("(%p)\n", hWndOwner
);
654 /* FIXME: use lpwstrReason */
655 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
658 TOKEN_PRIVILEGES npr
;
660 /* enable the shutdown privilege for the current process */
661 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
663 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
664 npr
.PrivilegeCount
= 1;
665 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
666 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
669 ExitWindowsEx(EWX_REBOOT
, uReason
);
676 /*************************************************************************
677 * LogoffWindowsDialog [SHELL32.54]
680 EXTERN_C
int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
682 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
683 ExitWindowsEx(EWX_LOGOFF
, 0);
689 /*************************************************************************
690 * RestartDialog [SHELL32.59]
693 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
695 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
699 /*************************************************************************
700 * ExitWindowsDialog [SHELL32.60]
703 * exported by ordinal
705 void WINAPI
ExitWindowsDialog(HWND hWndOwner
)
707 TRACE("(%p)\n", hWndOwner
);
709 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
712 TOKEN_PRIVILEGES npr
;
714 /* enable shutdown privilege for current process */
715 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
717 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
718 npr
.PrivilegeCount
= 1;
719 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
720 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
723 ExitWindowsEx(EWX_SHUTDOWN
, 0);