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 IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxProcess
, wxEvtHandler
)
70 #define wxEXECUTE_WIN_MESSAGE 10000
72 struct wxExecuteData
{
81 static DWORD
wxExecuteThread(wxExecuteData
*data
)
83 WaitForSingleObject(data
->process
, INFINITE
);
85 // Send an implicit message to the window
86 SendMessage(data
->window
, wxEXECUTE_WIN_MESSAGE
, 0, (LPARAM
)data
);
93 LRESULT APIENTRY _EXPORT
wxExecuteWindowCbk(HWND hWnd
, UINT message
,
94 WPARAM wParam
, LPARAM lParam
)
96 wxExecuteData
*data
= (wxExecuteData
*)lParam
;
98 if (message
== wxEXECUTE_WIN_MESSAGE
) {
101 data
->handler
->OnTerminate((int)data
->process
);
111 extern char wxPanelClassName
[];
113 long wxExecute(const wxString
& command
, bool sync
, wxProcess
*handler
)
128 // copy the command line
129 clen
= command
.Length();
130 if (!clen
) return -1;
131 cl
= (char *) calloc( 1, 256);
133 strcpy( cl
, WXSTRINGCAST command
);
135 // isolate command and arguments
136 argp
= strchr( cl
, ' ');
141 result
= ShellExecute((HWND
) (wxTheApp
->GetTopWindow() ? (HWND
) wxTheApp
->GetT
142 opWindow()->GetHWND() : NULL
),
143 (const wchar_t) "open", (const wchar_t) cl
, (const wchar_t) arg
145 (const wchar_t) NULL
, SW_SHOWNORMAL
);
147 result
= ShellExecute( (HWND
) (wxTheApp
->GetTopWindow() ? wxTheApp
->GetTopWindow()->GetHWND() : NULL
),
148 "open", cl
, argp
, NULL
, SW_SHOWNORMAL
);
151 if (((long)result
) <= 32) {
157 data
= new wxExecuteData
;
160 window
= CreateWindow(wxPanelClassName
, NULL
, 0, 0, 0, 0, 0, NULL
,
161 (HMENU
) NULL
, wxGetInstance(), 0);
163 FARPROC ExecuteWindowInstance
= MakeProcInstance((FARPROC
) wxExecuteWindowCbk
,
166 SetWindowLong(window
, GWL_WNDPROC
, (LONG
) ExecuteWindowInstance
);
167 SetWindowLong(window
, GWL_USERDATA
, (LONG
) data
);
169 data
->process
= result
;
170 data
->window
= window
;
172 data
->handler
= (sync
) ? NULL
: handler
;
174 dresult
= (DWORD
)CreateThread(NULL
, 0,
175 (LPTHREAD_START_ROUTINE
)wxExecuteThread
,
176 (void *)data
, 0, &tid
);
178 wxDebugMsg("wxExecute PANIC: I can't create the waiting thread !");
179 DestroyWindow(window
);
189 // waiting until command executed
196 long instanceID
= WinExec((LPCSTR
) WXSTRINGCAST command
, SW_SHOW
);
197 if (instanceID
< 32) return(0);
203 running
= GetModuleUsage((HANDLE
)instanceID
);
210 // DUMMIES TO SATISFY THE LINKER UNTIL GUILHEM FINISHES THE CODE
211 wxProcess::wxProcess(wxEvtHandler
*parent
, int id
)
215 wxProcess::~wxProcess()
219 void wxProcess::OnTerminate(int pid
)
223 wxProcessEvent::wxProcessEvent(int id
, int pid
)