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", 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
== -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
== 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 [SHELL32.61]
267 * Original name: RunFileDlg (exported by ordinal)
269 void WINAPI
RunFileDlg(
272 LPCSTR lpstrDirectory
,
274 LPCSTR lpstrDescription
,
278 RUNFILEDLGPARAMS rfdp
;
283 rfdp
.hwndOwner
= hwndOwner
;
285 rfdp
.lpstrDirectory
= lpstrDirectory
;
286 rfdp
.lpstrTitle
= lpstrTitle
;
287 rfdp
.lpstrDescription
= lpstrDescription
;
288 rfdp
.uFlags
= uFlags
;
290 if(!(hRes
= FindResourceA(shell32_hInstance
, "SHELL_RUN_DLG", (LPSTR
)RT_DIALOG
)))
292 MessageBoxA (hwndOwner
, "Couldn't find dialog.", "Nix", MB_OK
) ;
295 if(!(template = (LPVOID
)LoadResource(shell32_hInstance
, hRes
)))
297 MessageBoxA (hwndOwner
, "Couldn't load dialog.", "Nix", MB_OK
) ;
301 DialogBoxIndirectParamA((HINSTANCE
)GetWindowLongPtrW( hwndOwner
,
303 template, hwndOwner
, RunDlgProc
, (LPARAM
)&rfdp
);
307 /* Dialog procedure for RunFileDlg */
308 static INT_PTR CALLBACK
RunDlgProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
311 char *psz
, *pdir
, szMsg
[256];
312 static RUNFILEDLGPARAMS
*prfdp
= NULL
;
317 prfdp
= (RUNFILEDLGPARAMS
*)lParam
;
319 if (prfdp
->lpstrTitle
)
320 SetWindowTextA (hwnd
, prfdp
->lpstrTitle
) ;
322 SetClassLongPtrW (hwnd
, GCLP_HICON
, (LPARAM
)prfdp
->hIcon
) ;
323 SendMessageW (GetDlgItem (hwnd
, 12297), STM_SETICON
,
324 (WPARAM
)LoadIconW (NULL
, (LPCWSTR
)IDI_WINLOGO
), 0);
325 FillList (GetDlgItem (hwnd
, 12298), NULL
) ;
326 SetFocus (GetDlgItem (hwnd
, 12298)) ;
330 switch (LOWORD (wParam
))
335 if ((ic
= GetWindowTextLengthA (htxt
= GetDlgItem (hwnd
, 12298))))
337 psz
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
338 GetWindowTextA (htxt
, psz
, ic
+ 1) ;
339 pdir
= HeapAlloc( GetProcessHeap(), 0, (ic
+ 2) );
344 ptr
= strrchr(pdir
+ 4, '\\');
350 if (ShellExecuteA(NULL
, NULL
, psz
, NULL
, pdir
, SW_SHOWNORMAL
) < (HINSTANCE
)33)
352 char *pszSysMsg
= NULL
;
354 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
355 FORMAT_MESSAGE_FROM_SYSTEM
|
356 FORMAT_MESSAGE_IGNORE_INSERTS
,
357 NULL
, GetLastError (),
358 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
359 (LPSTR
)&pszSysMsg
, 0, NULL
361 sprintf (szMsg
, "Error: %s", pszSysMsg
) ;
362 LocalFree ((HLOCAL
)pszSysMsg
) ;
363 MessageBoxA (hwnd
, szMsg
, NULL
, MB_OK
| MB_ICONEXCLAMATION
) ;
365 HeapFree(GetProcessHeap(), 0, psz
);
366 HeapFree(GetProcessHeap(), 0, pdir
);
367 SendMessageA (htxt
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
370 FillList (htxt
, psz
) ;
371 HeapFree(GetProcessHeap(), 0, psz
);
372 HeapFree(GetProcessHeap(), 0, pdir
);
373 EndDialog (hwnd
, 0) ;
378 EndDialog (hwnd
, 0) ;
383 HMODULE hComdlg
= NULL
;
384 LPFNOFN ofnProc
= NULL
;
385 static char szFName
[1024] = "", szFileTitle
[256] = "", szInitDir
[768] = "" ;
386 static OPENFILENAMEA ofn
=
388 sizeof (OPENFILENAMEA
),
391 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
401 OFN_ENABLESIZING
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
,
410 ofn
.hwndOwner
= hwnd
;
412 if (NULL
== (hComdlg
= LoadLibraryExA ("comdlg32", NULL
, 0)))
414 MessageBoxA (hwnd
, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
418 if ((LPFNOFN
)NULL
== (ofnProc
= (LPFNOFN
)GetProcAddress (hComdlg
, "GetOpenFileNameA")))
420 MessageBoxA (hwnd
, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK
| MB_ICONEXCLAMATION
) ;
426 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
427 SetWindowTextA (GetDlgItem (hwnd
, 12298), szFName
) ;
428 SendMessageA (GetDlgItem (hwnd
, 12298), CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
429 SetFocus (GetDlgItem (hwnd
, IDOK
)) ;
431 FreeLibrary (hComdlg
) ;
441 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
442 static void FillList (HWND hCb
, char *pszLatest
)
445 /* char szDbgMsg[256] = "" ; */
446 char *pszList
= NULL
, *pszCmd
= NULL
, cMatch
= 0, cMax
= 0x60, szIndex
[2] = "-" ;
447 DWORD icList
= 0, icCmd
= 0 ;
450 SendMessageA (hCb
, CB_RESETCONTENT
, 0, 0) ;
452 if (ERROR_SUCCESS
!= RegCreateKeyExA (
453 HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
454 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
455 MessageBoxA (hCb
, "Unable to open registry key !", "Nix", MB_OK
) ;
457 RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, NULL
, &icList
) ;
461 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
462 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, "MRUList", NULL
, NULL
, (LPBYTE
)pszList
, &icList
))
463 MessageBoxA (hCb
, "Unable to grab MRUList !", "Nix", MB_OK
) ;
468 pszList
= HeapAlloc( GetProcessHeap(), 0, icList
) ;
472 for (Nix
= 0 ; Nix
< icList
- 1 ; Nix
++)
474 if (pszList
[Nix
] > cMax
)
475 cMax
= pszList
[Nix
] ;
477 szIndex
[0] = pszList
[Nix
] ;
479 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, NULL
, &icCmd
))
480 MessageBoxA (hCb
, "Unable to grab size of index", "Nix", MB_OK
) ;
482 pszCmd
= HeapReAlloc(GetProcessHeap(), 0, pszCmd
, icCmd
) ;
484 pszCmd
= HeapAlloc(GetProcessHeap(), 0, icCmd
) ;
485 if (ERROR_SUCCESS
!= RegQueryValueExA (hkey
, szIndex
, NULL
, NULL
, (LPBYTE
)pszCmd
, &icCmd
))
486 MessageBoxA (hCb
, "Unable to grab index", "Nix", MB_OK
) ;
488 if (NULL
!= pszLatest
)
490 if (!lstrcmpiA(pszCmd
, pszLatest
))
493 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
494 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
496 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszCmd
) ;
497 SetWindowTextA (hCb
, pszCmd
) ;
498 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
500 cMatch
= pszList
[Nix
] ;
501 memmove (&pszList
[1], pszList
, Nix
) ;
502 pszList
[0] = cMatch
;
507 if (26 != icList
- 1 || icList
- 2 != Nix
|| cMatch
|| NULL
== pszLatest
)
510 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
511 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
513 SendMessageA (hCb
, CB_ADDSTRING
, 0, (LPARAM
)pszCmd
) ;
516 SetWindowTextA (hCb
, pszCmd
) ;
517 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
524 sprintf (szDbgMsg, "Doing loop thing.\n") ;
525 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
527 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
528 SetWindowTextA (hCb
, pszLatest
) ;
529 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
531 cMatch
= pszList
[Nix
] ;
532 memmove (&pszList
[1], pszList
, Nix
) ;
533 pszList
[0] = cMatch
;
534 szIndex
[0] = cMatch
;
535 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
539 if (!cMatch
&& NULL
!= pszLatest
)
542 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
543 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
545 SendMessageA (hCb
, CB_INSERTSTRING
, 0, (LPARAM
)pszLatest
) ;
546 SetWindowTextA (hCb
, pszLatest
) ;
547 SendMessageA (hCb
, CB_SETEDITSEL
, 0, MAKELPARAM (0, -1)) ;
551 pszList
= HeapReAlloc(GetProcessHeap(), 0, pszList
, ++icList
) ;
553 pszList
= HeapAlloc(GetProcessHeap(), 0, ++icList
) ;
554 memmove (&pszList
[1], pszList
, icList
- 1) ;
555 pszList
[0] = cMatch
;
556 szIndex
[0] = cMatch
;
557 RegSetValueExA (hkey
, szIndex
, 0, REG_SZ
, (LPBYTE
)pszLatest
, strlen (pszLatest
) + 1) ;
560 RegSetValueExA (hkey
, "MRUList", 0, REG_SZ
, (LPBYTE
)pszList
, strlen (pszList
) + 1) ;
562 HeapFree( GetProcessHeap(), 0, pszCmd
) ;
563 HeapFree( GetProcessHeap(), 0, pszList
) ;
567 /*************************************************************************
568 * ConfirmDialog [internal]
570 * Put up a confirm box, return TRUE if the user confirmed
572 static BOOL
ConfirmDialog(HWND hWndOwner
, UINT PromptId
, UINT TitleId
)
577 LoadStringW(shell32_hInstance
, PromptId
, Prompt
, sizeof(Prompt
) / sizeof(WCHAR
));
578 LoadStringW(shell32_hInstance
, TitleId
, Title
, sizeof(Title
) / sizeof(WCHAR
));
579 return MessageBoxW(hWndOwner
, Prompt
, Title
, MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
583 /*************************************************************************
584 * RestartDialogEx [SHELL32.730]
587 int WINAPI
RestartDialogEx(HWND hWndOwner
, LPCWSTR lpwstrReason
, DWORD uFlags
, DWORD uReason
)
589 TRACE("(%p)\n", hWndOwner
);
591 /* FIXME: use lpwstrReason */
592 if (ConfirmDialog(hWndOwner
, IDS_RESTART_PROMPT
, IDS_RESTART_TITLE
))
595 TOKEN_PRIVILEGES npr
;
597 /* enable the shutdown privilege for the current process */
598 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
600 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
601 npr
.PrivilegeCount
= 1;
602 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
603 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
606 ExitWindowsEx(EWX_REBOOT
, uReason
);
612 /*************************************************************************
613 * LogoffWindowsDialog [SHELL32.54]
616 int WINAPI
LogoffWindowsDialog(HWND hWndOwner
)
618 if (ConfirmDialog(hWndOwner
, IDS_LOGOFF_PROMPT
, IDS_LOGOFF_TITLE
))
620 ExitWindowsEx(EWX_LOGOFF
, 0);
625 /*************************************************************************
626 * RestartDialog [SHELL32.59]
629 int WINAPI
RestartDialog(HWND hWndOwner
, LPCWSTR lpstrReason
, DWORD uFlags
)
631 return RestartDialogEx(hWndOwner
, lpstrReason
, uFlags
, 0);
635 /*************************************************************************
636 * ExitWindowsDialog [SHELL32.60]
639 * exported by ordinal
641 void WINAPI
ExitWindowsDialog (HWND hWndOwner
)
643 TRACE("(%p)\n", hWndOwner
);
645 if (ConfirmDialog(hWndOwner
, IDS_SHUTDOWN_PROMPT
, IDS_SHUTDOWN_TITLE
))
648 TOKEN_PRIVILEGES npr
;
650 /* enable shutdown privilege for current process */
651 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
653 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
654 npr
.PrivilegeCount
= 1;
655 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
656 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
659 ExitWindowsEx(EWX_SHUTDOWN
, 0);