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 "utils.h"
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
{
75 static DWORD
wxExecuteThread(wxExecuteData
*data
)
77 WaitForSingleObject(data
->process
, INFINITE
);
79 // Send an implicit message to the window
80 SendMessage(data
->window
, wxEXECUTE_WIN_MESSAGE
, 0, (LPARAM
)data
);
85 LRESULT APIENTRY _EXPORT
wxExecuteWindowCbk(HWND hWnd
, UINT message
,
86 WPARAM wParam
, LPARAM lParam
)
88 wxExecuteData
*data
= (wxExecuteData
*)lParam
;
90 if (message
== wxEXECUTE_WIN_MESSAGE
) {
93 data
->handler
->OnTerminate((int)data
->process
);
103 extern char wxPanelClassName
[];
105 long wxExecute(const wxString
& command
, bool sync
, wxProcess
*handler
)
120 // copy the command line
121 clen
= command
.Length();
122 if (!clen
) return -1;
123 cl
= (char *) calloc( 1, 256);
125 strcpy( cl
, WXSTRINGCAST command
);
127 // isolate command and arguments
128 argp
= strchr( cl
, ' ');
133 result
= ShellExecute((HWND
) (wxTheApp
->GetTopWindow() ? (HWND
) wxTheApp
->GetT
134 opWindow()->GetHWND() : NULL
),
135 (const wchar_t) "open", (const wchar_t) cl
, (const wchar_t) arg
137 (const wchar_t) NULL
, SW_SHOWNORMAL
);
139 result
= ShellExecute( (HWND
) (wxTheApp
->GetTopWindow() ? wxTheApp
->GetTopWindow()->GetHWND() : NULL
),
140 "open", cl
, argp
, NULL
, SW_SHOWNORMAL
);
143 if (((long)result
) <= 32) {
149 data
= new wxExecuteData
;
152 window
= CreateWindow(wxPanelClassName
, NULL
, 0, 0, 0, 0, 0, NULL
,
153 (HMENU
) NULL
, wxGetInstance(), 0);
155 FARPROC ExecuteWindowInstance
= MakeProcInstance((FARPROC
) wxExecuteWindowCbk
,
158 SetWindowLong(window
, GWL_WNDPROC
, (LONG
) ExecuteWindowInstance
);
159 SetWindowLong(window
, GWL_USERDATA
, (LONG
) data
);
161 data
->process
= result
;
162 data
->window
= window
;
164 data
->handler
= (sync
) ? NULL
: handler
;
166 dresult
= (DWORD
)CreateThread(NULL
, 0,
167 (LPTHREAD_START_ROUTINE
)wxExecuteThread
,
168 (void *)data
, 0, &tid
);
170 wxDebugMsg("wxExecute PANIC: I can't create the waiting thread !");
171 DestroyWindow(window
);
181 // waiting until command executed
188 long instanceID
= WinExec((LPCSTR
) WXSTRINGCAST command
, SW_SHOW
);
189 if (instanceID
< 32) return(0);
195 running
= GetModuleUsage((HANDLE
)instanceID
);