Reputation: 33813
I have made the following application:
As you seen when clicking on the settings button in the parent window opens a new child window called "settings", but when closing that child window unfortunately, It is not closed and remain hidden. And when open the child window again it creates another an instance of child window and so on.
The problem is when closing the parent window it does not close and remains in task manager -> processes
.
// Creates an instance of child window
void mainfrm::settings_btnOnButtonClick(wxCommandEvent & event) {
this->settingWindow = new settingsfrm(this);
settingWindow->ShowModal();
}
// When closing the child window
void settingsfrm::cancel_btnOnButtonClick(wxCommandEvent & event) {
this->EndModal(0);
}
// When destroying the variable that contains the instance of child window
mainfrm::~mainfrm() {
settingWindow = NULL;
delete settingWindow;
}
Upvotes: 0
Views: 502
Reputation: 3554
According to the documentation:
the modal dialog is one of the very few examples of wxWindow-derived objects which may be created on the stack and not on the heap
So your first block of code can be written like this instead (assuming settingsfrm is derived from wxDialog):
// Creates an instance of child window
void mainfrm::settings_btnOnButtonClick(wxCommandEvent & event) {
settingsfrm settingWindow(this);
int i = settingWindow.ShowModal();
//if necessary, do something with i here
}
Your main application frame will sit and wait while settingWindow is shown and then settingWindow delete itself when it goes out of scope. There shouldn't be a need to store a pointer for settingWindow in your main frame.
Upvotes: 1