Application-wide cleanup code Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
steven.pyae
In need of some credit
In need of some credit
Posts: 8
Joined: Wed Dec 04, 2019 9:08 am

Application-wide cleanup code

Post by steven.pyae » Wed Dec 04, 2019 9:16 am

Hi,

I am quite new to Programming and coding for about 1 month now.
I have read up on the following link about destroying windows and applications
https://docs.wxwidgets.org/3.0/overview ... on_exitapp
However there is one topic that I couldn't understand "Exiting the Application Gracefully"

How or Where Can I Implement this? I want to reset everything when I close the application via "X" mark on the application or the "QUIT" from the Menu Bar. I have implemented the following code on my Main.cpp

Code: Select all

//QUITTING THE APPLICATION via 'X' on the Window
void cMain::OnQuit(wxCloseEvent& WXUNUSED(event))
{
	if (wxMessageBox("Are you sure you want to close the Application?", "Close Application", wxICON_QUESTION | wxYES_NO) == wxYES)
		Destroy();
	else
		return;
}
//QUITTING THE APPLICATION via 'Quit' on the menubar 
void cMain::OnMenuQuit(wxCommandEvent& mext) 
{
	if (wxMessageBox("Are you sure you want to close the Application?", "Close Application", wxICON_QUESTION | wxYES_NO) == wxYES)
		Destroy();
	else
		return;
}
Will Destroy() sufficient for me to close the application as well as clear any used memory space during the application usage?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3579
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Application-wide cleanup code

Post by ONEEYEMAN » Wed Dec 04, 2019 1:40 pm

Hi,
Please check the code inside "minimal" sample.

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 14285
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Application-wide cleanup code

Post by doublemax » Wed Dec 04, 2019 1:53 pm

Assuming "cMain" is a wxFrame, just calling Close() should be enough.

Why? Because the default behavior of a wxFrame is to destroy itself when it gets closed *and* the default behavior of a wxApp is to terminate when the last toplevel window (like a wxFrame) gets closed.
Use the source, Luke!

steven.pyae
In need of some credit
In need of some credit
Posts: 8
Joined: Wed Dec 04, 2019 9:08 am

Re: Application-wide cleanup code

Post by steven.pyae » Thu Dec 05, 2019 1:23 am

Hi ONEEYEMAN,
Which 'Mimimal" example are you talking about?

Hi doublemax, Thank you for the answer, I will try it out.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3579
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Application-wide cleanup code

Post by ONEEYEMAN » Thu Dec 05, 2019 1:32 pm

Hi,
The code is inside wxWidgets\samples\minimal\minimal.cpp.

Build it, run it and study the code.

Thank you.

Post Reply