Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / A question about wxProcess ??

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. A question about wxProcess ??
#3856
Posted by: Aison 2004-04-16 17:32:15
I use a pointor of wxProcess to execute a new process,but I don't know when the process finish,the code is like this:
wxProcess *proc;
proc = wxProcess::Open("BurnCDv3Win.exe "); 

I want to do something else only when the process has finished,but my process "BurnCD v3Win.exe" doesn't have return value. now what should I do,how to know when the process has finished?

Waiting for your answer,thank you!
Message2. Re: A question about wxProcess ??
#3861
Posted by: guidance 2004-04-17 07:17:53
Did you try what the doc says (OnTerminate etc.)?

http://g.yi.org/_scripts/search.php?search=wxprocess
Message3. Re: A question about wxProcess ??
#3869
Posted by: upCASE 2004-04-18 19:14:09
Hi!
I'd say you'll have three solutions:
1. Execute the process synchronously, meaning your "master" process will stop till the child process has ended.
2. Derive your own process class from wxProcess and override OnTerminate.
3. Use wxProcessEvent.

The last one should be the easiest.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message4. Re: A question about wxProcess ??
#3873
Posted by: Aison 2004-04-19 12:05:21
to upCASE:
    thank you,
    but how to use the third way to solve the problem?
Message5. Re: A question about wxProcess ??
#3878
Posted by: upCASE 2004-04-20 03:39:56
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!
Message6. Re: A question about wxProcess ??
#3879
Posted by: Aison 2004-04-20 14:49:01
to upCase:
    Thank you for your solution,I have solve the problem!
    Thanks!
Message7. A new question about wxMenuBar ??
#4042
Posted by: 2004-05-06 07:53:37
While running my program, I noticed that if I use my short cut keys, i.e. Atl E for my edit menu, that if I entered another shortcut like Atl F while the first selection was highlighted, it will over-write the first shortcut command.  Would anyone have a clue as to why this is happening. 

Shortcut commands can be over-written during runtime.

example:

I set my first menu item, in File Menu, to be the print command with "Ctrl P" as the shortcut.  So, I would type "Alt F" to highlight the File menu, then, if I type another command like "Ctrl X", the first item in the list of menu items will change to be Ctrl X, in this case, "Ctrl P" is now "Ctrl X". 

Do anyone know how I can prevent this from happening?
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2024-12-10  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0