What I want to achieve is to have a progress dialog that I create when my main window is created, and store in the background, showing it when I need it, then hide again. Obviously it should destroy on application exit.
Here's parts of my code (the whole project is currently several thousand lines of code and copyrighted, so can't post it all, hope this is enough to spot an error):
Code: Select all
class MainWnd : public wxFrame
{
public:
wxProgressDialog* progDlg;
// Other code
};
Code: Select all
MainWnd::MainWnd(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(350, 200))
{
// Add this window's user interface
wxPanel* panel = new wxPanel(this);
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
panel->SetSizer(topSizer);
wxButton* run_button = new wxButton(panel, wxID_INFO, wxT("Run test"));
wxButton* quit_button = new wxButton(panel, wxID_EXIT, wxT("Quit"));
buttonSizer->Add(run_button, 0, wxALIGN_CENTRE | wxALL, 20 );
buttonSizer->Add(quit_button, 0, wxALIGN_CENTRE | wxALL, 20 );
topSizer->Add(buttonSizer, 1, wxALIGN_CENTER);
// Add dialogs
progDlg = new wxProgressDialog("Send data", "Sender...", 100, this, 0); // !!!!!!NOTE THIS LINE!!!!!
// Connect to event handlers
Bind(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainWnd::OnBtnPressRun), this, wxID_INFO);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainWnd::OnBtnPressQuit), this, wxID_EXIT);
Bind(wxEVT_TIMER, wxTimerEventHandler(MainWnd::OnTimer), this);
Bind(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MainWnd::OnClose), this);
// Size and place window
topSizer->SetSizeHints(this);
Centre();
}
Code: Select all
// What to do on close
void MainWnd::OnClose(wxCloseEvent& event)
{
m_timer->Stop(); // Timer that runs a function every 50ms. This function might access GUI,
// so I stop the timer before destroying anything. Program is single-threaded.
// Other stuff here, not GUI related
this->Destroy();
}
So, what happens with this code is:
1. My progress dialog is displayed immediately
2. My progress dialog is not destroyed when I close the main window
What I've tried to do to fix the above problems:
1. Call progDlg->Show(false) after constructing it - didn't help
2. Play around with the parent argument as well as the wxPD_APP_MODAL style flag - didn't help
3. Destroy progDlg manually (using progDlg->Destroy() in the MainWnd::OnClose function) - with or without using the main window as parent. This partially worked, in the sense that the progress dialog disappeared, but the application process did not terminate.
Any ideas?