1、覆盖问题
2、销毁
重载OnCancel和PostNcDestroy函数
CModeLess.cpp
将Create第二个参数改成GetDesktopWindow()可解决
// 防止非模态对话框重复创建
CWnd* pWnd = FindWindow(0, "caption"); //caption对话框名
if(NULL == pWnd)
{
CDialog* dlg = new CDialog();
dlg->Create(IDD_DIALOG1, GetDesktopWindow());
dlg->ShowWindow(SW_SHOW);
}
else
{
pWnd->BringWindowToTop();
}
2、销毁
重载OnCancel和PostNcDestroy函数
CModeLess.h文件
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
afx_msg void OnCancel();
afx_msg void PostNcDestroy();
CModeLess.cpp
void CModeLess::OnCancel()
{
DestroyWindow();
}
void CModeLess::PostNcDestroy()
{
CDialogEx::PostNcDestroy();
delete this;
}
本文详细介绍了在C++中通过修改窗口创建参数和重载特定函数来解决非模态对话框重复创建的问题,并阐述了如何正确地进行对话框的销毁操作,确保程序资源的有效管理。
1956

被折叠的 条评论
为什么被折叠?



