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"
29 #include "wine/debug.h"
33 #include "shell32_main.h"
34 #include "undocshell.h"
40 LPCSTR lpstrDirectory ;
42 LPCSTR lpstrDescription ;
46 typedef BOOL (*LPFNOFN) (OPENFILENAMEA *) ;
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
49 INT_PTR CALLBACK RunDlgProc (HWND, UINT, WPARAM, LPARAM) ;
50 void FillList (HWND, char *) ;
53 /*************************************************************************
54 * PickIconDlg [SHELL32.62]
57 BOOL WINAPI PickIconDlg(
61 LPDWORD lpdwIconIndex)
63 FIXME("(%p,%s,%08lx,%p):stub.\n",
64 hwndOwner, lpstrFile, nMaxFile,lpdwIconIndex);
68 /*************************************************************************
69 * RunFileDlg [SHELL32.61]
72 * Original name: RunFileDlg (exported by ordinal)
74 void WINAPI RunFileDlg(
77 LPCSTR lpstrDirectory,
79 LPCSTR lpstrDescription,
83 RUNFILEDLGPARAMS rfdp;
88 rfdp.hwndOwner = hwndOwner;
90 rfdp.lpstrDirectory = lpstrDirectory;
91 rfdp.lpstrTitle = lpstrTitle;
92 rfdp.lpstrDescription = lpstrDescription;
95 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_RUN_DLG", RT_DIALOGA)))
97 MessageBoxA (hwndOwner, "Couldn't find dialog.", "Nix", MB_OK) ;
100 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
102 MessageBoxA (hwndOwner, "Couldn't load dialog.", "Nix", MB_OK) ;
106 DialogBoxIndirectParamA((HINSTANCE)GetWindowLongA( hwndOwner,
108 template, hwndOwner, RunDlgProc, (LPARAM)&rfdp);
112 /* Dialog procedure for RunFileDlg */
113 INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
116 char *psz, szMsg[256] ;
117 static RUNFILEDLGPARAMS *prfdp = NULL ;
122 prfdp = (RUNFILEDLGPARAMS *)lParam ;
123 SetWindowTextA (hwnd, prfdp->lpstrTitle) ;
124 SetClassLongA (hwnd, GCL_HICON, (LPARAM)prfdp->hIcon) ;
125 SendMessageA (GetDlgItem (hwnd, 12297), STM_SETICON, (WPARAM)LoadIconA (NULL, IDI_WINLOGOA), 0) ;
126 FillList (GetDlgItem (hwnd, 12298), NULL) ;
127 SetFocus (GetDlgItem (hwnd, 12298)) ;
133 PROCESS_INFORMATION pi ;
135 si.cb = sizeof (STARTUPINFOA) ;
136 si.lpReserved = NULL ;
137 si.lpDesktop = NULL ;
143 si.dwXCountChars = 0 ;
144 si.dwYCountChars = 0 ;
145 si.dwFillAttribute = 0 ;
148 si.lpReserved2 = NULL ;
150 switch (LOWORD (wParam))
155 if ((ic = GetWindowTextLengthA (htxt = GetDlgItem (hwnd, 12298))))
157 psz = malloc (ic + 2) ;
158 GetWindowTextA (htxt, psz, ic + 1) ;
160 if (!CreateProcessA (NULL, psz, NULL, NULL, TRUE,
161 NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
163 char *pszSysMsg = NULL ;
165 FORMAT_MESSAGE_ALLOCATE_BUFFER |
166 FORMAT_MESSAGE_FROM_SYSTEM |
167 FORMAT_MESSAGE_IGNORE_INSERTS,
168 NULL, GetLastError (),
169 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
170 (LPSTR)&pszSysMsg, 0, NULL
172 sprintf (szMsg, "Error: %s", pszSysMsg) ;
173 LocalFree ((HLOCAL)pszSysMsg) ;
174 MessageBoxA (hwnd, szMsg, "Nix", MB_OK | MB_ICONEXCLAMATION) ;
177 SendMessageA (htxt, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
180 FillList (htxt, psz) ;
182 EndDialog (hwnd, 0) ;
187 EndDialog (hwnd, 0) ;
192 HMODULE hComdlg = NULL ;
193 LPFNOFN ofnProc = NULL ;
194 static char szFName[1024] = "", szFileTitle[256] = "", szInitDir[768] = "" ;
195 static OPENFILENAMEA ofn =
197 sizeof (OPENFILENAMEA),
200 "Executable Files\0*.exe\0All Files\0*.*\0\0\0\0",
210 OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
219 ofn.hwndOwner = hwnd ;
221 if (NULL == (hComdlg = LoadLibraryExA ("comdlg32", NULL, 0)))
223 MessageBoxA (hwnd, "Unable to display dialog box (LoadLibraryEx) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
227 if ((LPFNOFN)NULL == (ofnProc = (LPFNOFN)GetProcAddress (hComdlg, "GetOpenFileNameA")))
229 MessageBoxA (hwnd, "Unable to display dialog box (GetProcAddress) !", "Nix", MB_OK | MB_ICONEXCLAMATION) ;
235 SetFocus (GetDlgItem (hwnd, IDOK)) ;
236 SetWindowTextA (GetDlgItem (hwnd, 12298), szFName) ;
237 SendMessageA (GetDlgItem (hwnd, 12298), CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
238 SetFocus (GetDlgItem (hwnd, IDOK)) ;
240 FreeLibrary (hComdlg) ;
251 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
252 void FillList (HWND hCb, char *pszLatest)
255 /* char szDbgMsg[256] = "" ; */
256 char *pszList = NULL, *pszCmd = NULL, cMatch = 0, cMax = 0x60, szIndex[2] = "-" ;
257 DWORD icList = 0, icCmd = 0 ;
260 SendMessageA (hCb, CB_RESETCONTENT, 0, 0) ;
262 if (ERROR_SUCCESS != RegCreateKeyExA (
263 HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
264 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL))
265 MessageBoxA (hCb, "Unable to open registry key !", "Nix", MB_OK) ;
267 RegQueryValueExA (hkey, "MRUList", NULL, NULL, NULL, &icList) ;
271 pszList = malloc (icList) ;
272 if (ERROR_SUCCESS != RegQueryValueExA (hkey, "MRUList", NULL, NULL, pszList, &icList))
273 MessageBoxA (hCb, "Unable to grab MRUList !", "Nix", MB_OK) ;
277 pszList = malloc (icList = 1) ;
281 for (Nix = 0 ; Nix < icList - 1 ; Nix++)
283 if (pszList[Nix] > cMax)
284 cMax = pszList[Nix] ;
286 szIndex[0] = pszList[Nix] ;
288 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, NULL, &icCmd))
289 MessageBoxA (hCb, "Unable to grab size of index", "Nix", MB_OK) ;
290 pszCmd = realloc (pszCmd, icCmd) ;
291 if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, pszCmd, &icCmd))
292 MessageBoxA (hCb, "Unable to grab index", "Nix", MB_OK) ;
294 if (NULL != pszLatest)
296 if (!strcasecmp (pszCmd, pszLatest))
299 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
300 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
302 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszCmd) ;
303 SetWindowTextA (hCb, pszCmd) ;
304 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
306 cMatch = pszList[Nix] ;
307 memmove (&pszList[1], pszList, Nix) ;
308 pszList[0] = cMatch ;
313 if (26 != icList - 1 || icList - 2 != Nix || cMatch || NULL == pszLatest)
316 sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
317 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
319 SendMessageA (hCb, CB_ADDSTRING, 0, (LPARAM)pszCmd) ;
322 SetWindowTextA (hCb, pszCmd) ;
323 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
330 sprintf (szDbgMsg, "Doing loop thing.\n") ;
331 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
333 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
334 SetWindowTextA (hCb, pszLatest) ;
335 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
337 cMatch = pszList[Nix] ;
338 memmove (&pszList[1], pszList, Nix) ;
339 pszList[0] = cMatch ;
340 szIndex[0] = cMatch ;
341 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
345 if (!cMatch && NULL != pszLatest)
348 sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
349 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
351 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
352 SetWindowTextA (hCb, pszLatest) ;
353 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
356 pszList = realloc (pszList, ++icList) ;
357 memmove (&pszList[1], pszList, icList - 1) ;
358 pszList[0] = cMatch ;
359 szIndex[0] = cMatch ;
360 RegSetValueExA (hkey, szIndex, 0, REG_SZ, pszLatest, strlen (pszLatest) + 1) ;
363 RegSetValueExA (hkey, "MRUList", 0, REG_SZ, pszList, strlen (pszList) + 1) ;
369 /*************************************************************************
370 * ExitWindowsDialog [SHELL32.60]
373 * exported by ordinal
375 void WINAPI ExitWindowsDialog (HWND hWndOwner)
377 TRACE("(%p)\n", hWndOwner);
378 if (MessageBoxA( hWndOwner, "Do you want to exit WINE?", "Shutdown", MB_YESNO|MB_ICONQUESTION) == IDYES)
380 SendMessageA ( hWndOwner, WM_QUIT, 0, 0);