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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
34 #include "wine/debug.h"
38 #include "shell32_main.h"
40 #include "undocshell.h"
46 LPCSTR lpstrDirectory ;
48 LPCSTR lpstrDescription ;
52 typedef BOOL (*LPFNOFN) (OPENFILENAMEA *) ;
54 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 INT_PTR CALLBACK RunDlgProc (HWND, UINT, WPARAM, LPARAM) ;
56 void FillList (HWND, char *) ;
59 /*************************************************************************
60 * PickIconDlg [SHELL32.62]
63 BOOL WINAPI PickIconDlg(
67 LPDWORD lpdwIconIndex)
69 FIXME("(%p,%s,%08lx,%p):stub.\n",
70 hwndOwner, lpstrFile, nMaxFile,lpdwIconIndex);
74 /*************************************************************************
75 * RunFileDlg [SHELL32.61]
78 * Original name: RunFileDlg (exported by ordinal)
80 void WINAPI RunFileDlg(
83 LPCSTR lpstrDirectory,
85 LPCSTR lpstrDescription,
89 RUNFILEDLGPARAMS rfdp;
94 rfdp.hwndOwner = hwndOwner;
96 rfdp.lpstrDirectory = lpstrDirectory;
97 rfdp.lpstrTitle = lpstrTitle;
98 rfdp.lpstrDescription = lpstrDescription;
101 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_RUN_DLG", (LPSTR)RT_DIALOG)))
103 MessageBoxA (hwndOwner, "Couldn't find dialog.", "Nix", MB_OK) ;
106 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
108 MessageBoxA (hwndOwner, "Couldn't load dialog.", "Nix", MB_OK) ;
112 DialogBoxIndirectParamA((HINSTANCE)GetWindowLongA( hwndOwner,
114 template, hwndOwner, RunDlgProc, (LPARAM)&rfdp);
118 /* Dialog procedure for RunFileDlg */
119 INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
122 char *psz, szMsg[256] ;
123 static RUNFILEDLGPARAMS *prfdp = NULL ;
128 prfdp = (RUNFILEDLGPARAMS *)lParam ;
129 SetWindowTextA (hwnd, prfdp->lpstrTitle) ;
130 SetClassLongA (hwnd, GCL_HICON, (LPARAM)prfdp->hIcon) ;
131 SendMessageA (GetDlgItem (hwnd, 12297), STM_SETICON,
132 (WPARAM)LoadIconA (NULL, (LPSTR)IDI_WINLOGO), 0);
133 FillList (GetDlgItem (hwnd, 12298), NULL) ;
134 SetFocus (GetDlgItem (hwnd, 12298)) ;
138 switch (LOWORD (wParam))
143 if ((ic = GetWindowTextLengthA (htxt = GetDlgItem (hwnd, 12298))))
145 psz = malloc (ic + 2) ;
146 GetWindowTextA (htxt, psz, ic + 1) ;
148 if (ShellExecuteA(NULL, "open", psz, NULL, NULL, SW_SHOWNORMAL) < (HINSTANCE)33)
150 char *pszSysMsg = NULL ;
152 FORMAT_MESSAGE_ALLOCATE_BUFFER |
153 FORMAT_MESSAGE_FROM_SYSTEM |
154 FORMAT_MESSAGE_IGNORE_INSERTS,
155 NULL, GetLastError (),
156 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
157 (LPSTR)&pszSysMsg, 0, NULL
159 sprintf (szMsg, "Error: %s", pszSysMsg) ;
160 LocalFree ((HLOCAL)pszSysMsg) ;
161 MessageBoxA (hwnd, szMsg, "Nix", MB_OK | MB_ICONEXCLAMATION) ;
164 SendMessageA (htxt, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
167 FillList (htxt, psz) ;
169 EndDialog (hwnd, 0) ;
174 EndDialog (hwnd, 0) ;
179 HMODULE hComdlg = NULL ;
180 LPFNOFN ofnProc = NULL ;
181 static char szFName[1024] = "", szFileTitle[256] = "", szInitDir[768] = "" ;
182 static OPENFILENAMEA ofn =
184 sizeof (OPENFILENAMEA),
187 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
197 OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
206 ofn.hwndOwner = hwnd ;
208 if (NULL == (hComdlg = LoadLibraryExA ("comdlg32", NULL, 0)))
210 MessageBoxA (hwnd, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
214 if ((LPFNOFN)NULL == (ofnProc = (LPFNOFN)GetProcAddress (hComdlg, "GetOpenFileNameA")))
216 MessageBoxA (hwnd, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
222 SetFocus (GetDlgItem (hwnd, IDOK)) ;
223 SetWindowTextA (GetDlgItem (hwnd, 12298), szFName) ;
224 SendMessageA (GetDlgItem (hwnd, 12298), CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
225 SetFocus (GetDlgItem (hwnd, IDOK)) ;
227 FreeLibrary (hComdlg) ;
237 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
238 void FillList (HWND hCb, char *pszLatest)
241 /* char szDbgMsg[256] = "" ; */
242 char *pszList = NULL, *pszCmd = NULL, cMatch = 0, cMax = 0x60, szIndex[2] = "-" ;
243 DWORD icList = 0, icCmd = 0 ;
246 SendMessageA (hCb, CB_RESETCONTENT, 0, 0) ;
248 if (ERROR_SUCCESS != RegCreateKeyExA (
249 HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
250 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL))
251 MessageBoxA (hCb, "Unable to open registry key !", "Nix", MB_OK) ;
253 RegQueryValueExA (hkey, "MRUList", NULL, NULL, NULL, &icList) ;
257 pszList = malloc (icList) ;
258 if (ERROR_SUCCESS != RegQueryValueExA (hkey, "MRUList", NULL, NULL, pszList, &icList))
259 MessageBoxA (hCb, "Unable to grab MRUList !", "Nix", MB_OK) ;
263 pszList = malloc (icList = 1) ;
267 for (Nix = 0 ; Nix < icList - 1 ; Nix++)
269 if (pszList[Nix] > cMax)
270 cMax = pszList[Nix] ;
272 szIndex[0] = pszList[Nix] ;
274 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, NULL, &icCmd))
275 MessageBoxA (hCb, "Unable to grab size of index", "Nix", MB_OK) ;
276 pszCmd = realloc (pszCmd, icCmd) ;
277 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, pszCmd, &icCmd))
278 MessageBoxA (hCb, "Unable to grab index", "Nix", MB_OK) ;
280 if (NULL != pszLatest)
282 if (!strcasecmp (pszCmd, pszLatest))
285 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
286 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
288 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszCmd) ;
289 SetWindowTextA (hCb, pszCmd) ;
290 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
292 cMatch = pszList[Nix] ;
293 memmove (&pszList[1], pszList, Nix) ;
294 pszList[0] = cMatch ;
299 if (26 != icList - 1 || icList - 2 != Nix || cMatch || NULL == pszLatest)
302 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
303 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
305 SendMessageA (hCb, CB_ADDSTRING, 0, (LPARAM)pszCmd) ;
308 SetWindowTextA (hCb, pszCmd) ;
309 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
316 sprintf (szDbgMsg, "Doing loop thing.\n") ;
317 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
319 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
320 SetWindowTextA (hCb, pszLatest) ;
321 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
323 cMatch = pszList[Nix] ;
324 memmove (&pszList[1], pszList, Nix) ;
325 pszList[0] = cMatch ;
326 szIndex[0] = cMatch ;
327 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
331 if (!cMatch && NULL != pszLatest)
334 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
335 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
337 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
338 SetWindowTextA (hCb, pszLatest) ;
339 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
342 pszList = realloc (pszList, ++icList) ;
343 memmove (&pszList[1], pszList, icList - 1) ;
344 pszList[0] = cMatch ;
345 szIndex[0] = cMatch ;
346 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
349 RegSetValueExA (hkey, "MRUList", 0, REG_SZ, pszList, strlen (pszList) + 1) ;
356 /*************************************************************************
357 * ConfirmDialog [internal]
359 * Put up a confirm box, return TRUE if the user confirmed
361 static BOOL ConfirmDialog(HWND hWndOwner, UINT PromptId, UINT TitleId)
366 LoadStringW(shell32_hInstance, PromptId, Prompt, sizeof(Prompt) / sizeof(WCHAR));
367 LoadStringW(shell32_hInstance, TitleId, Title, sizeof(Title) / sizeof(WCHAR));
368 return MessageBoxW(hWndOwner, Prompt, Title, MB_YESNO|MB_ICONQUESTION) == IDYES;
372 /*************************************************************************
373 * RestartDialogEx [SHELL32.730]
376 int WINAPI RestartDialogEx(HWND hWndOwner, LPCWSTR lpwstrReason, DWORD uFlags, DWORD uReason)
378 TRACE("(%p)\n", hWndOwner);
380 /*FIXME: use uReason */
382 if (ConfirmDialog(hWndOwner, IDS_RESTART_PROMPT, IDS_RESTART_TITLE))
385 TOKEN_PRIVILEGES npr;
387 /* enable shutdown privilege for current process */
388 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
390 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
391 npr.PrivilegeCount = 1;
392 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
393 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
396 ExitWindowsEx(EWX_REBOOT, 0);
403 /*************************************************************************
404 * RestartDialog [SHELL32.59]
407 int WINAPI RestartDialog(HWND hWndOwner, LPCWSTR lpstrReason, DWORD uFlags)
409 return RestartDialogEx(hWndOwner, lpstrReason, uFlags, 0);
413 /*************************************************************************
414 * ExitWindowsDialog [SHELL32.60]
417 * exported by ordinal
419 void WINAPI ExitWindowsDialog (HWND hWndOwner)
421 TRACE("(%p)\n", hWndOwner);
423 if (ConfirmDialog(hWndOwner, IDS_SHUTDOWN_PROMPT, IDS_SHUTDOWN_TITLE))
426 TOKEN_PRIVILEGES npr;
428 /* enable shutdown privilege for current process */
429 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
431 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
432 npr.PrivilegeCount = 1;
433 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
434 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
437 ExitWindowsEx(EWX_SHUTDOWN, 0);