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 LPCSTR lpstrDirectory
;
30 LPCSTR lpstrDescription
;
34 typedef BOOL (*LPFNOFN
) (OPENFILENAMEA
*) ;
36 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
37 static INT_PTR CALLBACK
RunDlgProc (HWND
, UINT
, WPARAM
, LPARAM
) ;
38 static void FillList (HWND
, char *) ;
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\n", 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 swprintf(szText
, L
"%u", pIconContext
->Index
);
127 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_FINDSTRING
, -1, (LPARAM
)szText
);
129 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, index
, 0);
132 switch(LOWORD(wParam
))
135 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
136 SendMessageW(pIconContext
->hDlgCtrl
, LB_GETTEXT
, index
, (LPARAM
)szText
);
137 pIconContext
->Index
= _wtoi(szText
);
138 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)pIconContext
->szName
);
139 DestroyIconList(pIconContext
->hDlgCtrl
);
140 EndDialog(hwndDlg
, 1);
143 DestroyIconList(pIconContext
->hDlgCtrl
);
144 EndDialog(hwndDlg
, 0);
146 case IDC_PICKICON_LIST
:
147 if (HIWORD(wParam
) == LBN_SELCHANGE
)
148 InvalidateRect((HWND
)lParam
, NULL
, TRUE
); // FIXME USE UPDATE RECT
150 case IDC_BUTTON_PATH
:
154 ofn
.lStructSize
= sizeof(ofn
);
155 ofn
.hwndOwner
= hwndDlg
;
156 ofn
.lpstrFile
= szText
;
157 ofn
.nMaxFile
= MAX_PATH
;
158 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(WCHAR
));
159 ofn
.lpstrTitle
= szTitle
;
160 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_FILTER
, szFilter
, sizeof(szFilter
) / sizeof(WCHAR
));
161 ofn
.lpstrFilter
= szFilter
;
162 if (GetOpenFileNameW(&ofn
))
166 if (!wcsicmp(pIconContext
->szName
, szText
))
169 DestroyIconList(pIconContext
->hDlgCtrl
);
171 hLibrary
= LoadLibraryExW(szText
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
172 if (hLibrary
== NULL
)
174 FreeLibrary(pIconContext
->hLibrary
);
175 pIconContext
->hLibrary
= hLibrary
;
176 wcscpy(pIconContext
->szName
, szText
);
177 EnumResourceNamesW(pIconContext
->hLibrary
, RT_ICON
, EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
178 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
179 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)szText
);
181 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)pIconContext
->szName
);
183 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
189 lpmis
= (LPMEASUREITEMSTRUCT
) lParam
;
190 lpmis
->itemHeight
= 32;
191 lpmis
->itemWidth
= 64;
194 lpdis
= (LPDRAWITEMSTRUCT
) lParam
;
195 if (lpdis
->itemID
== -1)
199 switch (lpdis
->itemAction
)
203 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
204 hIcon
=(HICON
)SendMessage(lpdis
->hwndItem
, LB_GETITEMDATA
, lpdis
->itemID
, (LPARAM
) 0);
206 if (lpdis
->itemID
== index
)
209 hBrush
= CreateSolidBrush(RGB(0, 0, 255));
210 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
211 DeleteObject(hBrush
);
216 hBrush
= CreateSolidBrush(RGB(255, 255, 255));
217 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
218 DeleteObject(hBrush
);
220 DrawIconEx(lpdis
->hDC
, lpdis
->rcItem
.left
,lpdis
->rcItem
.top
, hIcon
,
234 BOOL WINAPI
PickIconDlg(
242 PICK_ICON_CONTEXT IconContext
;
244 hLibrary
= LoadLibraryExW(lpstrFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
245 IconContext
.hLibrary
= hLibrary
;
246 IconContext
.Index
= *lpdwIconIndex
;
247 wcscpy(IconContext
.szName
, lpstrFile
);
249 res
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_PICK_ICON_DIALOG
), hwndOwner
, PickIconProc
, (LPARAM
)&IconContext
);
252 wcscpy(lpstrFile
, IconContext
.szName
);
253 *lpdwIconIndex
= IconContext
.Index
;
256 FreeLibrary(hLibrary
);
260 /*************************************************************************
261 * RunFileDlg [SHELL32.61]
264 * Original name: RunFileDlg (exported by ordinal)
266 void WINAPI
RunFileDlg(
269 LPCSTR lpstrDirectory
,
271 LPCSTR lpstrDescription
,
275 RUNFILEDLGPARAMS rfdp
;
280 rfdp
.hwndOwner
= hwndOwner
;
282 rfdp
.lpstrDirectory
= lpstrDirectory
;
283 rfdp
.lpstrTitle
= lpstrTitle
;
284 rfdp
.lpstrDescription
= lpstrDescription
;
285 rfdp
.uFlags
= uFlags
;
287 if(!(hRes
= FindResourceA(shell32_hInstance
, "SHELL_RUN_DLG", (LPSTR
)RT_DIALOG
)))
289 MessageBoxA (hwndOwner
, "Couldn't find dialog.", "Nix", MB_OK
) ;
292 if(!(template = (LPVOID
)LoadResource(shell32_hInstance
, hRes
)))
294 MessageBoxA (hwndOwner
, "Couldn't load dialog.", "Nix", MB_OK
) ;
298 DialogBoxIndirectParamA((HINSTANCE
)GetWindowLongPtrW( hwndOwner
,
300 template, hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
304 /* Dialog procedure for RunFileDlg */
305 static INT_PTR CALLBACK
RunDlgProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
308 char *psz
, *pdir
, szMsg
[256];
309 static RUNFILEDLGPARAMS
*prfdp
= NULL
;
314 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
316 if (prfdp
->lpstrTitle
)
317 SetWindowTextA (hwnd
, prfdp
->lpstrTitle
) ;
319 SetClassLongPtrW (hwnd
, GCLP_HICON
, (LPARAM
)prfdp
->hIcon
) ;
320 SendMessageW (GetDlgItem (hwnd
, 12297), STM_SETICON
,
321 (WPARAM
)LoadIconW (NULL
, (LPCWSTR
)IDI_WINLOGO
), 0);
322 FillList (GetDlgItem (hwnd
, 12298), NULL
) ;
323 SetFocus (GetDlgItem (hwnd
, 12298)) ;
327 switch (LOWORD (wParam
))
332 if ((ic
= GetWindowTextLengthA (htxt
= GetDlgItem (hwnd
, 12298))))
334 psz
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
335 GetWindowTextA (htxt
, psz
, ic
+ 1) ;
336 pdir
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
341 ptr
= strrchr(pdir
+ 4, '\\');
347 if (ShellExecuteA(NULL
, NULL
, psz
, NULL
, pdir
, SW_SHOWNORMAL
) < (HINSTANCE
)33)
349 char *pszSysMsg
= NULL
;
351 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
352 FORMAT_MESSAGE_FROM_SYSTEM
|
353 FORMAT_MESSAGE_IGNORE_INSERTS
,
354 NULL
, GetLastError (),
355 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
356 (LPSTR
)&pszSysMsg
, 0, NULL
358 sprintf (szMsg
, "Error: %s", pszSysMsg
) ;
359 LocalFree ((HLOCAL
)pszSysMsg
) ;
360 MessageBoxA (hwnd
, szMsg
, NULL
, MB_OK
| MB_ICONEXCLAMATION
) ;
362 HeapFree(GetProcessHeap(), 0, psz
);
363 HeapFree(GetProcessHeap(), 0, pdir
);
364 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
367 FillList (htxt
, psz
) ;
368 HeapFree(GetProcessHeap(), 0, psz
);
369 HeapFree(GetProcessHeap(), 0, pdir
);
370 EndDialog (hwnd
, 0) ;
375 EndDialog (hwnd
, 0) ;
380 HMODULE hComdlg
= NULL
;
381 LPFNOFN ofnProc
= NULL
;
382 static char szFName
[1024] = "", szFileTitle
[256] = "", szInitDir
[768] = "" ;
383 static OPENFILENAMEA ofn
=
385 sizeof (OPENFILENAMEA
),
388 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
398 OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
,
407 ofn
.hwndOwner
= hwnd
;
409 if (NULL
== (hComdlg
= LoadLibraryExA ("comdlg32", NULL
, 0)))
411 MessageBoxA (hwnd
, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
415 if ((LPFNOFN
)NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameA")))
417 MessageBoxA (hwnd
, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
423 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
424 SetWindowTextA (GetDlgItem (hwnd
, 12298), szFName
) ;
425 SendMessageA (GetDlgItem (hwnd
, 12298), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
426 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
428 FreeLibrary (hComdlg
) ;
438 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
439 static void FillList (HWND hCb
, char *pszLatest
)
442 /* char szDbgMsg[256] = "" ; */
443 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
444 DWORD icList
= 0, icCmd
= 0 ;
447 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
449 if (ERROR_SUCCESS
!= RegCreateKeyExA (
450 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
451 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
452 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
454 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
458 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
459 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
460 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
) ;
465 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
469 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
471 if (pszList
[Nix
] > cMax
)
472 cMax
= pszList
[Nix
] ;
474 szIndex
[0] = pszList
[Nix
] ;
476 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
477 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
479 pszCmd
= HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
481 pszCmd
= HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
482 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
483 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
485 if (NULL
!= pszLatest
)
487 if (!lstrcmpiA(pszCmd
, pszLatest
))
490 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
491 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
493 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
494 SetWindowTextA (hCb
, pszCmd
) ;
495 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
497 cMatch
= pszList
[Nix
] ;
498 memmove (&pszList
[1], pszList
, Nix
) ;
499 pszList
[0] = cMatch
;
504 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
507 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
508 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
510 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
513 SetWindowTextA (hCb
, pszCmd
) ;
514 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
521 sprintf (szDbgMsg, "Doing loop thing.\n") ;
522 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
524 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
525 SetWindowTextA (hCb
, pszLatest
) ;
526 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
528 cMatch
= pszList
[Nix
] ;
529 memmove (&pszList
[1], pszList
, Nix
) ;
530 pszList
[0] = cMatch
;
531 szIndex
[0] = cMatch
;
532 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
536 if (!cMatch
&& NULL
!= pszLatest
)
539 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
540 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
542 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
543 SetWindowTextA (hCb
, pszLatest
) ;
544 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
548 pszList
= HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
550 pszList
= HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
551 memmove (&pszList
[1], pszList
, icList
- 1) ;
552 pszList
[0] = cMatch
;
553 szIndex
[0] = cMatch
;
554 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
557 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
559 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
560 HeapFree( GetProcessHeap(), 0, pszList
) ;
564 /*************************************************************************
565 * ConfirmDialog [internal]
567 * Put up a confirm box, return TRUE if the user confirmed
569 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
574 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
575 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
576 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
580 /*************************************************************************
581 * RestartDialogEx [SHELL32.730]
584 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
586 TRACE("(%p)\n", hWndOwner
);
588 /* FIXME: use lpwstrReason */
589 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
592 TOKEN_PRIVILEGES npr
;
594 /* enable the shutdown privilege for the current process */
595 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
597 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
598 npr
.PrivilegeCount
= 1;
599 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
600 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
603 ExitWindowsEx(EWX_REBOOT
, uReason
);
609 /*************************************************************************
610 * LogoffWindowsDialog [SHELL32.54]
613 int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
615 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
617 ExitWindowsEx(EWX_LOGOFF
, 0);
622 /*************************************************************************
623 * RestartDialog [SHELL32.59]
626 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
628 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
632 /*************************************************************************
633 * ExitWindowsDialog [SHELL32.60]
636 * exported by ordinal
638 void WINAPI
ExitWindowsDialog (HWND hWndOwner
)
640 TRACE("(%p)\n", hWndOwner
);
642 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
645 TOKEN_PRIVILEGES npr
;
647 /* enable shutdown privilege for current process */
648 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
650 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
651 npr
.PrivilegeCount
= 1;
652 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
653 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
656 ExitWindowsEx(EWX_SHUTDOWN
, 0);