close all window Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
farso92
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Jun 06, 2014 3:54 pm

close all window

Post by farso92 »

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?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: close all window

Post by PB »

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.
farso92
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Jun 06, 2014 3:54 pm

Re: close all window

Post by farso92 »

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.
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?

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;

}
quit metod of second

Code: Select all

void SecondWindow::OnSecondQuit()
{
	Destroy();
	return;
}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: close all window

Post by PB »

If I wanted to close the main window when the secondary one is closed, I would do it like this:

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)
Simple and works.
farso92
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Jun 06, 2014 3:54 pm

Re: close all window

Post by farso92 »

thank you
Post Reply