1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/msw/private.h"
40 #include <sys/unistd.h>
60 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
66 #define wxEXECUTE_WIN_MESSAGE 10000
68 struct wxExecuteData
{
77 static DWORD
wxExecuteThread(wxExecuteData
*data
)
79 WaitForSingleObject(data
->process
, INFINITE
);
81 // Send an implicit message to the window
82 SendMessage(data
->window
, wxEXECUTE_WIN_MESSAGE
, 0, (LPARAM
)data
);
89 LRESULT APIENTRY _EXPORT
wxExecuteWindowCbk(HWND hWnd
, UINT message
,
90 WPARAM wParam
, LPARAM lParam
)
92 wxExecuteData
*data
= (wxExecuteData
*)lParam
;
94 if (message
== wxEXECUTE_WIN_MESSAGE
) {
97 data
->handler
->OnTerminate((int)data
->process
);
107 extern char wxPanelClassName
[];
109 long wxExecute(const wxString
& command
, bool sync
, wxProcess
*handler
)
124 // copy the command line
125 clen
= command
.Length();
126 if (!clen
) return -1;
127 cl
= (char *) calloc( 1, 256);
129 strcpy( cl
, WXSTRINGCAST command
);
131 // isolate command and arguments
132 argp
= strchr( cl
, ' ');
137 result
= ShellExecute((HWND
) (wxTheApp
->GetTopWindow() ? (HWND
) wxTheApp
->GetTopWindow()->GetHWND() : NULL
),
138 (const wchar_t) "open", (const wchar_t) cl
, (const wchar_t) argp
,
139 (const wchar_t) NULL
, SW_SHOWNORMAL
);
141 result
= ShellExecute( (HWND
) (wxTheApp
->GetTopWindow() ? wxTheApp
->GetTopWindow()->GetHWND() : NULL
),
142 "open", cl
, argp
, NULL
, SW_SHOWNORMAL
);
145 if (((long)result
) <= 32) {
151 data
= new wxExecuteData
;
154 window
= CreateWindow(wxPanelClassName
, NULL
, 0, 0, 0, 0, 0, NULL
,
155 (HMENU
) NULL
, wxGetInstance(), 0);
157 FARPROC ExecuteWindowInstance
= MakeProcInstance((FARPROC
) wxExecuteWindowCbk
,
160 SetWindowLong(window
, GWL_WNDPROC
, (LONG
) ExecuteWindowInstance
);
161 SetWindowLong(window
, GWL_USERDATA
, (LONG
) data
);
163 data
->process
= result
;
164 data
->window
= window
;
166 data
->handler
= (sync
) ? NULL
: handler
;
168 dresult
= (DWORD
)CreateThread(NULL
, 0,
169 (LPTHREAD_START_ROUTINE
)wxExecuteThread
,
170 (void *)data
, 0, &tid
);
172 wxDebugMsg("wxExecute PANIC: I can't create the waiting thread !");
173 DestroyWindow(window
);
183 // waiting until command executed
190 long instanceID
= WinExec((LPCSTR
) WXSTRINGCAST command
, SW_SHOW
);
191 if (instanceID
< 32) return(0);
197 running
= GetModuleUsage((HANDLE
)instanceID
);