1 From 22c27dd3125b74a6383b466fe89f260bbe559fbf Mon Sep 17 00:00:00 2001
2 From: Vincent Povirk <vincent@codeweavers.com>
3 Date: Tue, 21 Oct 2008 16:07:47 -0500
4 Subject: [PATCH] shell32: try to guess the working directory in the run dialog
6 The Run dialog on Windows, when invoked from the start menu or by
7 passing NULL as a working directory to RunFileDlg, sets the working
8 directory to the parent of the file being run. Programs often rely on
9 the working directory so we should copy this behavior.
11 dlls/shell32/dialogs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++-
12 1 files changed, 50 insertions(+), 2 deletions(-)
14 diff --git a/dlls/shell32/dialogs.c b/dlls/shell32/dialogs.c
15 index b64d306..089c8c0 100644
16 --- a/dlls/shell32/dialogs.c
17 +++ b/dlls/shell32/dialogs.c
18 @@ -113,6 +113,47 @@ void WINAPI RunFileDlgW(
22 +/* find the directory that contains the file being run */
23 +static LPWSTR RunDlg_GetParentDir(LPCWSTR cmdline)
26 + WCHAR *dest, *result, *result_end=NULL;
28 + result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*strlenW(cmdline));
41 + DWORD attrs = GetFileAttributesW(result);
42 + if (attrs != INVALID_FILE_ATTRIBUTES && attrs & FILE_ATTRIBUTE_DIRECTORY)
58 + HeapFree(GetProcessHeap(), 0, result);
63 /* Dialog procedure for RunFileDlg */
64 static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
66 @@ -158,14 +199,20 @@ static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPAR
67 HWND htxt = GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH);
68 if ((ic = GetWindowTextLengthW (htxt)))
71 + WCHAR *psz, *parent=NULL ;
72 + LPCWSTR working_dir ;
73 psz = HeapAlloc( GetProcessHeap(), 0, (ic + 1)*sizeof(WCHAR) );
74 GetWindowTextW (htxt, psz, ic + 1) ;
76 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
77 * WM_NOTIFY before execution */
79 - if (ShellExecuteW(hwnd, NULL, psz, NULL, prfdp->lpstrDirectory, SW_SHOWNORMAL) < (HINSTANCE)33)
80 + if (prfdp->lpstrDirectory)
81 + working_dir = prfdp->lpstrDirectory;
83 + working_dir = parent = RunDlg_GetParentDir(psz);
85 + if (ShellExecuteW(hwnd, NULL, psz, NULL, working_dir, SW_SHOWNORMAL) < (HINSTANCE)33)
87 char *pszSysMsg = NULL ;
89 @@ -191,6 +238,7 @@ static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPAR
90 FillList (htxt, (LPSTR)psz, FALSE) ;
92 HeapFree(GetProcessHeap(), 0, psz);
93 + HeapFree(GetProcessHeap(), 0, parent);