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"
39 #include "undocshell.h"
45 LPCSTR lpstrDirectory ;
47 LPCSTR lpstrDescription ;
51 typedef BOOL (*LPFNOFN) (OPENFILENAMEA *) ;
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 INT_PTR CALLBACK RunDlgProc (HWND, UINT, WPARAM, LPARAM) ;
55 void FillList (HWND, char *) ;
58 /*************************************************************************
59 * PickIconDlg [SHELL32.62]
62 BOOL WINAPI PickIconDlg(
66 LPDWORD lpdwIconIndex)
68 FIXME("(%p,%s,%08lx,%p):stub.\n",
69 hwndOwner, lpstrFile, nMaxFile,lpdwIconIndex);
73 /*************************************************************************
74 * RunFileDlg [SHELL32.61]
77 * Original name: RunFileDlg (exported by ordinal)
79 void WINAPI RunFileDlg(
82 LPCSTR lpstrDirectory,
84 LPCSTR lpstrDescription,
88 RUNFILEDLGPARAMS rfdp;
93 rfdp.hwndOwner = hwndOwner;
95 rfdp.lpstrDirectory = lpstrDirectory;
96 rfdp.lpstrTitle = lpstrTitle;
97 rfdp.lpstrDescription = lpstrDescription;
100 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_RUN_DLG", RT_DIALOGA)))
102 MessageBoxA (hwndOwner, "Couldn't find dialog.", "Nix", MB_OK) ;
105 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
107 MessageBoxA (hwndOwner, "Couldn't load dialog.", "Nix", MB_OK) ;
111 DialogBoxIndirectParamA((HINSTANCE)GetWindowLongA( hwndOwner,
113 template, hwndOwner, RunDlgProc, (LPARAM)&rfdp);
117 /* Dialog procedure for RunFileDlg */
118 INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
121 char *psz, szMsg[256] ;
122 static RUNFILEDLGPARAMS *prfdp = NULL ;
127 prfdp = (RUNFILEDLGPARAMS *)lParam ;
128 SetWindowTextA (hwnd, prfdp->lpstrTitle) ;
129 SetClassLongA (hwnd, GCL_HICON, (LPARAM)prfdp->hIcon) ;
130 SendMessageA (GetDlgItem (hwnd, 12297), STM_SETICON, (WPARAM)LoadIconA (NULL, IDI_WINLOGOA), 0) ;
131 FillList (GetDlgItem (hwnd, 12298), NULL) ;
132 SetFocus (GetDlgItem (hwnd, 12298)) ;
138 PROCESS_INFORMATION pi ;
140 si.cb = sizeof (STARTUPINFOA) ;
141 si.lpReserved = NULL ;
142 si.lpDesktop = NULL ;
148 si.dwXCountChars = 0 ;
149 si.dwYCountChars = 0 ;
150 si.dwFillAttribute = 0 ;
153 si.lpReserved2 = NULL ;
155 switch (LOWORD (wParam))
160 if ((ic = GetWindowTextLengthA (htxt = GetDlgItem (hwnd, 12298))))
162 psz = malloc (ic + 2) ;
163 GetWindowTextA (htxt, psz, ic + 1) ;
165 if (!CreateProcessA (NULL, psz, NULL, NULL, TRUE,
166 NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
168 char *pszSysMsg = NULL ;
170 FORMAT_MESSAGE_ALLOCATE_BUFFER |
171 FORMAT_MESSAGE_FROM_SYSTEM |
172 FORMAT_MESSAGE_IGNORE_INSERTS,
173 NULL, GetLastError (),
174 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
175 (LPSTR)&pszSysMsg, 0, NULL
177 sprintf (szMsg, "Error: %s", pszSysMsg) ;
178 LocalFree ((HLOCAL)pszSysMsg) ;
179 MessageBoxA (hwnd, szMsg, "Nix", MB_OK | MB_ICONEXCLAMATION) ;
182 SendMessageA (htxt, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
185 FillList (htxt, psz) ;
187 EndDialog (hwnd, 0) ;
192 EndDialog (hwnd, 0) ;
197 HMODULE hComdlg = NULL ;
198 LPFNOFN ofnProc = NULL ;
199 static char szFName[1024] = "", szFileTitle[256] = "", szInitDir[768] = "" ;
200 static OPENFILENAMEA ofn =
202 sizeof (OPENFILENAMEA),
205 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
215 OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
224 ofn.hwndOwner = hwnd ;
226 if (NULL == (hComdlg = LoadLibraryExA ("comdlg32", NULL, 0)))
228 MessageBoxA (hwnd, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
232 if ((LPFNOFN)NULL == (ofnProc = (LPFNOFN)GetProcAddress (hComdlg, "GetOpenFileNameA")))
234 MessageBoxA (hwnd, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
240 SetFocus (GetDlgItem (hwnd, IDOK)) ;
241 SetWindowTextA (GetDlgItem (hwnd, 12298), szFName) ;
242 SendMessageA (GetDlgItem (hwnd, 12298), CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
243 SetFocus (GetDlgItem (hwnd, IDOK)) ;
245 FreeLibrary (hComdlg) ;
256 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
257 void FillList (HWND hCb, char *pszLatest)
260 /* char szDbgMsg[256] = "" ; */
261 char *pszList = NULL, *pszCmd = NULL, cMatch = 0, cMax = 0x60, szIndex[2] = "-" ;
262 DWORD icList = 0, icCmd = 0 ;
265 SendMessageA (hCb, CB_RESETCONTENT, 0, 0) ;
267 if (ERROR_SUCCESS != RegCreateKeyExA (
268 HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
269 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL))
270 MessageBoxA (hCb, "Unable to open registry key !", "Nix", MB_OK) ;
272 RegQueryValueExA (hkey, "MRUList", NULL, NULL, NULL, &icList) ;
276 pszList = malloc (icList) ;
277 if (ERROR_SUCCESS != RegQueryValueExA (hkey, "MRUList", NULL, NULL, pszList, &icList))
278 MessageBoxA (hCb, "Unable to grab MRUList !", "Nix", MB_OK) ;
282 pszList = malloc (icList = 1) ;
286 for (Nix = 0 ; Nix < icList - 1 ; Nix++)
288 if (pszList[Nix] > cMax)
289 cMax = pszList[Nix] ;
291 szIndex[0] = pszList[Nix] ;
293 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, NULL, &icCmd))
294 MessageBoxA (hCb, "Unable to grab size of index", "Nix", MB_OK) ;
295 pszCmd = realloc (pszCmd, icCmd) ;
296 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, pszCmd, &icCmd))
297 MessageBoxA (hCb, "Unable to grab index", "Nix", MB_OK) ;
299 if (NULL != pszLatest)
301 if (!strcasecmp (pszCmd, pszLatest))
304 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
305 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
307 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszCmd) ;
308 SetWindowTextA (hCb, pszCmd) ;
309 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
311 cMatch = pszList[Nix] ;
312 memmove (&pszList[1], pszList, Nix) ;
313 pszList[0] = cMatch ;
318 if (26 != icList - 1 || icList - 2 != Nix || cMatch || NULL == pszLatest)
321 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
322 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
324 SendMessageA (hCb, CB_ADDSTRING, 0, (LPARAM)pszCmd) ;
327 SetWindowTextA (hCb, pszCmd) ;
328 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
335 sprintf (szDbgMsg, "Doing loop thing.\n") ;
336 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
338 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
339 SetWindowTextA (hCb, pszLatest) ;
340 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
342 cMatch = pszList[Nix] ;
343 memmove (&pszList[1], pszList, Nix) ;
344 pszList[0] = cMatch ;
345 szIndex[0] = cMatch ;
346 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
350 if (!cMatch && NULL != pszLatest)
353 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
354 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
356 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
357 SetWindowTextA (hCb, pszLatest) ;
358 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
361 pszList = realloc (pszList, ++icList) ;
362 memmove (&pszList[1], pszList, icList - 1) ;
363 pszList[0] = cMatch ;
364 szIndex[0] = cMatch ;
365 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
368 RegSetValueExA (hkey, "MRUList", 0, REG_SZ, pszList, strlen (pszList) + 1) ;
374 /*************************************************************************
375 * ExitWindowsDialog [SHELL32.60]
378 * exported by ordinal
380 void WINAPI ExitWindowsDialog (HWND hWndOwner)
382 TRACE("(%p)\n", hWndOwner);
383 if (MessageBoxA( hWndOwner, "Do you want to exit WINE?", "Shutdown", MB_YESNO|MB_ICONQUESTION) == IDYES)
385 SendMessageA ( hWndOwner, WM_QUIT, 0, 0);