Hi! Try this and have a look at the Exec example. Header:
#ifndef __BASE_H
#define __BASE_H
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/process.h>
class MainApp: public wxApp
{
public:
virtual bool OnInit();
};
class MainFrame: public wxFrame
{
public:
MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
void OnQuit(wxCommandEvent &event);
void OnProcessStart(wxCommandEvent& evt);
void OnProcessEnd(wxProcessEvent& evt);
private:
DECLARE_EVENT_TABLE()
};
enum
{
ID_MAINWIN_QUIT = wxID_HIGHEST+1,
ID_MAINWIN_Process
};
#endif
Source:
#include "base.h"
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit()
{
MainFrame *win = new MainFrame("Frame", wxPoint (100, 100),
wxSize(450, 340));
win->Show(TRUE);
SetTopWindow(win);
return TRUE;
}
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(ID_MAINWIN_QUIT, MainFrame::OnQuit)
EVT_MENU(ID_MAINWIN_Process, MainFrame::OnProcessStart)
EVT_END_PROCESS(123, MainFrame::OnProcessEnd)
END_EVENT_TABLE()
MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame((wxFrame *) NULL, -1, title, pos, size)
{
wxMenu *FileMenu = new wxMenu;
wxMenuBar *MenuBar = new wxMenuBar;
FileMenu->Append(ID_MAINWIN_Process, "&Start new Process");
FileMenu->AppendSeparator();
FileMenu->Append(ID_MAINWIN_QUIT, "&Quit");
MenuBar->Append(FileMenu, "&File");
SetMenuBar(MenuBar);
CreateStatusBar(1);
SetStatusText("Hello World!");
}
void MainFrame::OnProcessStart(wxCommandEvent & WXUNUSED(event))
{
wxProcess* p = new wxProcess(this,123);
long pid = wxExecute("dir *.*",wxEXEC_ASYNC, p);
wxLogStatus("Process %ld started", pid);
}
void MainFrame::OnProcessEnd(wxProcessEvent& evt)
{
wxLogStatus("Process %d ended with exitcode %d", evt.GetPid(),evt.GetExitCode());
}
void MainFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
{
Close(TRUE);
}
upCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |