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
22 #include "wine/port.h"
34 #include "wine/debug.h"
38 #include "shell32_main.h"
40 #include "undocshell.h"
47 LPCSTR lpstrDirectory
;
49 LPCSTR lpstrDescription
;
53 typedef BOOL (*LPFNOFN
) (OPENFILENAMEA
*) ;
55 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
56 static INT_PTR CALLBACK
RunDlgProc (HWND
, UINT
, WPARAM
, LPARAM
) ;
57 static void FillList (HWND
, char *) ;
60 /*************************************************************************
61 * PickIconDlg [SHELL32.62]
69 WCHAR szName
[MAX_PATH
];
71 }PICK_ICON_CONTEXT
, *PPICK_ICON_CONTEXT
;
73 BOOL CALLBACK
EnumPickIconResourceProc(HMODULE hModule
,
82 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
84 if (IS_INTRESOURCE(lpszName
))
85 swprintf(szName
, L
"%u\n", lpszName
);
87 wcscpy(szName
, (WCHAR
*)lpszName
);
90 hIcon
= LoadIconW(pIconContext
->hLibrary
, (LPCWSTR
)lpszName
);
94 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_ADDSTRING
, 0, (LPARAM
)szName
);
96 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETITEMDATA
, index
, (LPARAM
)hIcon
);
102 DestroyIconList(HWND hDlgCtrl
)
107 count
= SendMessage(hDlgCtrl
, LB_GETCOUNT
, 0, 0);
111 for(index
= 0; index
< count
; index
++)
113 HICON hIcon
= (HICON
)SendMessageW(hDlgCtrl
, LB_GETITEMDATA
, index
, 0);
118 INT_PTR CALLBACK
PickIconProc(HWND hwndDlg
,
124 LPMEASUREITEMSTRUCT lpmis
;
125 LPDRAWITEMSTRUCT lpdis
;
128 WCHAR szText
[MAX_PATH
], szTitle
[100], szFilter
[100];
129 OPENFILENAMEW ofn
= {0};
131 PPICK_ICON_CONTEXT pIconContext
= (PPICK_ICON_CONTEXT
)GetWindowLong(hwndDlg
, DWLP_USER
);
136 pIconContext
= (PPICK_ICON_CONTEXT
)lParam
;
137 SetWindowLong(hwndDlg
, DWLP_USER
, (LONG
)pIconContext
);
138 pIconContext
->hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_PICKICON_LIST
);
139 EnumResourceNamesW(pIconContext
->hLibrary
, MAKEINTRESOURCEW(RT_ICON
), EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
140 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
141 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)szText
);
143 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)pIconContext
->szName
);
145 swprintf(szText
, L
"%u", pIconContext
->Index
);
146 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_FINDSTRING
, -1, (LPARAM
)szText
);
148 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, index
, 0);
151 switch(LOWORD(wParam
))
154 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
155 SendMessageW(pIconContext
->hDlgCtrl
, LB_GETTEXT
, index
, (LPARAM
)szText
);
156 pIconContext
->Index
= _wtoi(szText
);
157 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)pIconContext
->szName
);
158 DestroyIconList(pIconContext
->hDlgCtrl
);
159 EndDialog(hwndDlg
, 1);
162 DestroyIconList(pIconContext
->hDlgCtrl
);
163 EndDialog(hwndDlg
, 0);
165 case IDC_PICKICON_LIST
:
166 if (HIWORD(wParam
) == LBN_SELCHANGE
)
167 InvalidateRect((HWND
)lParam
, NULL
, TRUE
); // FIXME USE UPDATE RECT
169 case IDC_BUTTON_PATH
:
173 ofn
.lStructSize
= sizeof(ofn
);
174 ofn
.hwndOwner
= hwndDlg
;
175 ofn
.lpstrFile
= szText
;
176 ofn
.nMaxFile
= MAX_PATH
;
177 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_TITLE
, szTitle
, sizeof(szTitle
) / sizeof(WCHAR
));
178 ofn
.lpstrTitle
= szTitle
;
179 LoadStringW(shell32_hInstance
, IDS_PICK_ICON_FILTER
, szFilter
, sizeof(szFilter
) / sizeof(WCHAR
));
180 ofn
.lpstrFilter
= szFilter
;
181 if (GetOpenFileNameW(&ofn
))
185 if (!wcsicmp(pIconContext
->szName
, szText
))
188 DestroyIconList(pIconContext
->hDlgCtrl
);
190 hLibrary
= LoadLibraryExW(szText
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
191 if (hLibrary
== NULL
)
193 FreeLibrary(pIconContext
->hLibrary
);
194 pIconContext
->hLibrary
= hLibrary
;
195 wcscpy(pIconContext
->szName
, szText
);
196 EnumResourceNamesW(pIconContext
->hLibrary
, MAKEINTRESOURCEW(RT_ICON
), EnumPickIconResourceProc
, (LPARAM
)pIconContext
);
197 if (PathUnExpandEnvStringsW(pIconContext
->szName
, szText
, MAX_PATH
))
198 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)szText
);
200 SendDlgItemMessageW(hwndDlg
, IDC_EDIT_PATH
, WM_SETTEXT
, 0, (LPARAM
)pIconContext
->szName
);
202 SendMessageW(pIconContext
->hDlgCtrl
, LB_SETCURSEL
, 0, 0);
208 lpmis
= (LPMEASUREITEMSTRUCT
) lParam
;
209 lpmis
->itemHeight
= 32;
210 lpmis
->itemWidth
= 64;
213 lpdis
= (LPDRAWITEMSTRUCT
) lParam
;
214 if (lpdis
->itemID
== -1)
218 switch (lpdis
->itemAction
)
222 index
= SendMessageW(pIconContext
->hDlgCtrl
, LB_GETCURSEL
, 0, 0);
223 hIcon
=(HICON
)SendMessage(lpdis
->hwndItem
, LB_GETITEMDATA
, lpdis
->itemID
, (LPARAM
) 0);
225 if (lpdis
->itemID
== index
)
228 hBrush
= CreateSolidBrush(RGB(0, 0, 255));
229 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
230 DeleteObject(hBrush
);
235 hBrush
= CreateSolidBrush(RGB(255, 255, 255));
236 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
237 DeleteObject(hBrush
);
239 DrawIconEx(lpdis
->hDC
, lpdis
->rcItem
.left
,lpdis
->rcItem
.top
, hIcon
,
252 BOOL WINAPI
PickIconDlg(
260 PICK_ICON_CONTEXT IconContext
;
262 hLibrary
= LoadLibraryExW(lpstrFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
| LOAD_LIBRARY_AS_IMAGE_RESOURCE
);
263 IconContext
.hLibrary
= hLibrary
;
264 IconContext
.Index
= *lpdwIconIndex
;
265 wcscpy(IconContext
.szName
, lpstrFile
);
267 res
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_PICK_ICON_DIALOG
), hwndOwner
, PickIconProc
, (LPARAM
)&IconContext
);
270 wcscpy(lpstrFile
, IconContext
.szName
);
271 *lpdwIconIndex
= IconContext
.Index
;
274 FreeLibrary(hLibrary
);
278 /*************************************************************************
279 * RunFileDlg [SHELL32.61]
282 * Original name: RunFileDlg (exported by ordinal)
284 void WINAPI
RunFileDlg(
287 LPCSTR lpstrDirectory
,
289 LPCSTR lpstrDescription
,
293 RUNFILEDLGPARAMS rfdp
;
298 rfdp
.hwndOwner
= hwndOwner
;
300 rfdp
.lpstrDirectory
= lpstrDirectory
;
301 rfdp
.lpstrTitle
= lpstrTitle
;
302 rfdp
.lpstrDescription
= lpstrDescription
;
303 rfdp
.uFlags
= uFlags
;
305 if(!(hRes
= FindResourceA(shell32_hInstance
, "SHELL_RUN_DLG", (LPSTR
)RT_DIALOG
)))
307 MessageBoxA (hwndOwner
, "Couldn't find dialog.", "Nix", MB_OK
) ;
310 if(!(template = (LPVOID
)LoadResource(shell32_hInstance
, hRes
)))
312 MessageBoxA (hwndOwner
, "Couldn't load dialog.", "Nix", MB_OK
) ;
316 DialogBoxIndirectParamA((HINSTANCE
)GetWindowLongPtrW( hwndOwner
,
318 template, hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
322 /* Dialog procedure for RunFileDlg */
323 static INT_PTR CALLBACK
RunDlgProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
326 char *psz
, *pdir
, szMsg
[256];
327 static RUNFILEDLGPARAMS
*prfdp
= NULL
;
332 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
333 SetWindowTextA (hwnd
, prfdp
->lpstrTitle
) ;
334 SetClassLongPtrW (hwnd
, GCLP_HICON
, (LPARAM
)prfdp
->hIcon
) ;
335 SendMessageW (GetDlgItem (hwnd
, 12297), STM_SETICON
,
336 (WPARAM
)LoadIconW (NULL
, (LPCWSTR
)IDI_WINLOGO
), 0);
337 FillList (GetDlgItem (hwnd
, 12298), NULL
) ;
338 SetFocus (GetDlgItem (hwnd
, 12298)) ;
342 switch (LOWORD (wParam
))
347 if ((ic
= GetWindowTextLengthA (htxt
= GetDlgItem (hwnd
, 12298))))
349 psz
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
350 GetWindowTextA (htxt
, psz
, ic
+ 1) ;
351 pdir
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
356 ptr
= strrchr(pdir
, '\\');
360 if (ShellExecuteA(NULL
, "open", psz
, NULL
, pdir
, SW_SHOWNORMAL
) < (HINSTANCE
)33)
362 char *pszSysMsg
= NULL
;
364 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
365 FORMAT_MESSAGE_FROM_SYSTEM
|
366 FORMAT_MESSAGE_IGNORE_INSERTS
,
367 NULL
, GetLastError (),
368 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
369 (LPSTR
)&pszSysMsg
, 0, NULL
371 sprintf (szMsg
, "Error: %s", pszSysMsg
) ;
372 LocalFree ((HLOCAL
)pszSysMsg
) ;
373 MessageBoxA (hwnd
, szMsg
, "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
375 HeapFree(GetProcessHeap(), 0, psz
);
376 HeapFree(GetProcessHeap(), 0, pdir
);
377 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
380 FillList (htxt
, psz
) ;
381 HeapFree(GetProcessHeap(), 0, psz
);
382 HeapFree(GetProcessHeap(), 0, pdir
);
383 EndDialog (hwnd
, 0) ;
388 EndDialog (hwnd
, 0) ;
393 HMODULE hComdlg
= NULL
;
394 LPFNOFN ofnProc
= NULL
;
395 static char szFName
[1024] = "", szFileTitle
[256] = "", szInitDir
[768] = "" ;
396 static OPENFILENAMEA ofn
=
398 sizeof (OPENFILENAMEA
),
401 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
411 OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
,
420 ofn
.hwndOwner
= hwnd
;
422 if (NULL
== (hComdlg
= LoadLibraryExA ("comdlg32", NULL
, 0)))
424 MessageBoxA (hwnd
, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
428 if ((LPFNOFN
)NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameA")))
430 MessageBoxA (hwnd
, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
436 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
437 SetWindowTextA (GetDlgItem (hwnd
, 12298), szFName
) ;
438 SendMessageA (GetDlgItem (hwnd
, 12298), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
439 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
441 FreeLibrary (hComdlg
) ;
451 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
452 static void FillList (HWND hCb
, char *pszLatest
)
455 /* char szDbgMsg[256] = "" ; */
456 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
457 DWORD icList
= 0, icCmd
= 0 ;
460 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
462 if (ERROR_SUCCESS
!= RegCreateKeyExA (
463 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
464 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
465 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
467 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
471 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
472 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
473 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
) ;
478 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
482 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
484 if (pszList
[Nix
] > cMax
)
485 cMax
= pszList
[Nix
] ;
487 szIndex
[0] = pszList
[Nix
] ;
489 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
490 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
492 pszCmd
= HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
494 pszCmd
= HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
495 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
496 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
498 if (NULL
!= pszLatest
)
500 if (!lstrcmpiA(pszCmd
, pszLatest
))
503 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
504 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
506 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
507 SetWindowTextA (hCb
, pszCmd
) ;
508 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
510 cMatch
= pszList
[Nix
] ;
511 memmove (&pszList
[1], pszList
, Nix
) ;
512 pszList
[0] = cMatch
;
517 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
520 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
521 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
523 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
526 SetWindowTextA (hCb
, pszCmd
) ;
527 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
534 sprintf (szDbgMsg, "Doing loop thing.\n") ;
535 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
537 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
538 SetWindowTextA (hCb
, pszLatest
) ;
539 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
541 cMatch
= pszList
[Nix
] ;
542 memmove (&pszList
[1], pszList
, Nix
) ;
543 pszList
[0] = cMatch
;
544 szIndex
[0] = cMatch
;
545 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
549 if (!cMatch
&& NULL
!= pszLatest
)
552 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
553 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
555 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
556 SetWindowTextA (hCb
, pszLatest
) ;
557 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
561 pszList
= HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
563 pszList
= HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
564 memmove (&pszList
[1], pszList
, icList
- 1) ;
565 pszList
[0] = cMatch
;
566 szIndex
[0] = cMatch
;
567 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
570 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
572 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
573 HeapFree( GetProcessHeap(), 0, pszList
) ;
577 /*************************************************************************
578 * ConfirmDialog [internal]
580 * Put up a confirm box, return TRUE if the user confirmed
582 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
587 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
588 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
589 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
593 /*************************************************************************
594 * RestartDialogEx [SHELL32.730]
597 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
599 TRACE("(%p)\n", hWndOwner
);
601 /* FIXME: use lpwstrReason */
602 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
605 TOKEN_PRIVILEGES npr
;
607 /* enable the shutdown privilege for the current process */
608 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
610 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
611 npr
.PrivilegeCount
= 1;
612 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
613 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
616 ExitWindowsEx(EWX_REBOOT
, uReason
);
622 /*************************************************************************
623 * LogoffWindowsDialog [SHELL32.54]
626 int WINAPI
LogoffWindowsDialog(DWORD uFlags
)
629 ExitWindowsEx(EWX_LOGOFF
, 0);
633 /*************************************************************************
634 * RestartDialog [SHELL32.59]
637 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
639 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
643 /*************************************************************************
644 * ExitWindowsDialog [SHELL32.60]
647 * exported by ordinal
649 void WINAPI
ExitWindowsDialog (HWND hWndOwner
)
651 TRACE("(%p)\n", hWndOwner
);
653 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
656 TOKEN_PRIVILEGES npr
;
658 /* enable shutdown privilege for current process */
659 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
661 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
662 npr
.PrivilegeCount
= 1;
663 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
664 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
667 ExitWindowsEx(EWX_SHUTDOWN
, 0);