close all window Topic is solved
close all window
hi guys...in my program i have 2 window: mainWindow and secondWindow....i want that when i close mainWindow with the classic cross in the upper right the program must close also secondWindow....can somebody help me?
Re: close all window
Perhaps the best way would be to add the wxCloseEvent handler for the secondWindow to the mainWindow.
By the way, this subforum should be only for wxDev-C++ related issues, not a generic wxWidgets ones.
By the way, this subforum should be only for wxDev-C++ related issues, not a generic wxWidgets ones.
Re: close all window
so i have to add a quit metod to mainWindow and in this one i put an other metod to close the second....like this?PB wrote:Perhaps the best way would be to add the wxCloseEvent handler for the secondWindow to the mainWindow.
By the way, this subforum should be only for wxDev-C++ related issues, not a generic wxWidgets ones.
quit metod of mainWindow
Code: Select all
Connect(wxID_EXIT, wxEVT_CLOSE_WINDOW,wxCommandEventHandler(MainWindow::OnMainQuit));
////////////////////////////////////////
void MainWindow::OnMainQuit(wxCloseEvent& event)
{
secondWindow->OnSecondQuit();
Destroy();
return;
}
Code: Select all
void SecondWindow::OnSecondQuit()
{
Destroy();
return;
}
Re: close all window
If I wanted to close the main window when the secondary one is closed, I would do it like this:
Simple and works.
Code: Select all
#include <wx/wx.h>
class MainFrame : public wxFrame
{
public:
MainFrame()
: wxFrame(NULL, wxID_ANY, _("Main frame"))
{
m_childFrame = new wxFrame(this, wxID_ANY, _("Child frame"));
m_childFrame->Show();
m_childFrame->Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnCloseChildFrame, this);
}
private:
wxFrame* m_childFrame;
void OnCloseChildFrame(wxCloseEvent& )
{
Destroy(); // destroys the child frame too, if the secondary window is not a child of the main window, one has to call its Destroy() here
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
(new MainFrame)->Show();
return true;
}
};
IMPLEMENT_APP(MyApp)
Re: close all window
thank you