关闭后如何销毁child window?
How to destroy the child window after closing?
我做了以下申请:
如您所见,单击 parent window 中的设置按钮会打开一个名为 "settings" 的新 child window,但是当关闭它时child window 不幸的是,它没有关闭并保持隐藏状态。当再次打开 child window 时,它会创建另一个 child window 的实例,依此类推。
问题是在关闭 parent window 时它没有关闭并保留在 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;
}
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
所以你的第一个代码块可以这样写(假设 settingsfrm 派生自 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
}
您的主应用程序框架将在显示 settingWindow 时等待,然后当 settingWindow 超出范围时自行删除。不需要在主框架中存储用于设置窗口的指针。
我做了以下申请:
如您所见,单击 parent window 中的设置按钮会打开一个名为 "settings" 的新 child window,但是当关闭它时child window 不幸的是,它没有关闭并保持隐藏状态。当再次打开 child window 时,它会创建另一个 child window 的实例,依此类推。
问题是在关闭 parent window 时它没有关闭并保留在 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;
}
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
所以你的第一个代码块可以这样写(假设 settingsfrm 派生自 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
}
您的主应用程序框架将在显示 settingWindow 时等待,然后当 settingWindow 超出范围时自行删除。不需要在主框架中存储用于设置窗口的指针。