Created
October 27, 2021 10:51
-
-
Save PBfordev/69d0b40e51b20f88e9b71846087cd3dd to your computer and use it in GitHub Desktop.
Tests whether wxProcess::OnTerminate() is called when the process is killed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wx/wx.h> | |
#include <wx/process.h> | |
class MyProcess : public wxProcess | |
{ | |
public: | |
void OnTerminate(int pid, int status) override | |
{ | |
wxLogMessage("OnTerminate(): pid = %d, status = %d", pid, status); | |
} | |
}; | |
class MyFrame : public wxFrame | |
{ | |
public: | |
MyFrame() : wxFrame(nullptr, wxID_ANY, "Test") | |
{ | |
wxLog::SetActiveTarget(new wxLogTextCtrl(new wxTextCtrl(this, wxID_ANY, wxEmptyString, | |
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2))); | |
if ( wxExecute("cmd", wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, &m_process) ) | |
{ | |
wxLogMessage("Process started, pid = %d.", m_process.GetPid()); | |
m_timer.SetOwner(this); | |
m_timer.StartOnce(3000); | |
wxLogMessage("Going to kill the process in 3 seconds."); | |
} | |
Bind(wxEVT_TIMER, [this](wxTimerEvent&) | |
{ | |
wxLogMessage("Attempting to kill the process..."); | |
if ( wxProcess::Kill(m_process.GetPid()) == wxKILL_OK ) | |
wxLogMessage("Process killed."); | |
else | |
wxLogError("Could not kill the process."); | |
} ); | |
} | |
private: | |
MyProcess m_process; | |
wxTimer m_timer; | |
}; | |
class MyApp : public wxApp | |
{ | |
bool OnInit() override | |
{ | |
(new MyFrame)->Show(); | |
return true; | |
} | |
}; wxIMPLEMENT_APP(MyApp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment