gpt4 book ai didi

c++ - 关闭后如何销毁子窗口?

转载 作者:行者123 更新时间:2023-11-28 04:44:55 24 4
gpt4 key购买 nike

我已提出以下申请:

如您所见,单击父窗口中的设置按钮会打开一个名为“设置”的新子窗口,但不幸的是,当关闭该子窗口时,它并未关闭并保持隐藏状态。当再次打开子窗口时,它会创建另一个子窗口的实例,依此类推。

问题是在关闭父窗口时它并没有关闭,而是保留在任务管理器 -> 进程中。

// 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 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

所以你的第一个代码块可以这样写(假设 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 超出范围时自行删除。不需要在主框架中存储用于设置窗口的指针。

关于c++ - 关闭后如何销毁子窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49449684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com