基于对话框app的析构函数问题。

chichujn 2011-01-25 12:39:06
由于有一些读写ini配置文件的工作要做,所以把::WritePrivateProfileString放到了对话框app的析构函数里,以前做基于视图的工程也是这么干的。不过这次比较囧的是貌似app的析构函数根本就没有执行。
类似以下代码:
CSrcCappExtendedApp::~CSrcCappExtendedApp()
{
AfxMessageBox(_T(""));
::WritePrivateProfileString(***);
}
...全文
308 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2011-01-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 chichujn 的回复:]
由于有一些读写ini配置文件的工作要做,所以把::WritePrivateProfileString放到了对话框app的析构函数里,以前做基于视图的工程也是这么干的。不过这次比较囧的是貌似app的析构函数根本就没有执行。
类似以下代码:
CSrcCappExtendedApp::~CSrcCappExtendedApp()
{
AfxMessageBox(_T(""));
::Write……
[/Quote]
把你的WritePrivateProfileString可以放到WM_CLOSE消息的响应函数中去
你妹的特盗不 2011-01-26
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 chichujn 的回复:]
CSrcCappExtendedApp::CSrcCappExtendedApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance

AfxMessageBox(_T("construction"));
}

CSrcCappExtende……
[/Quote]

这个 exitinstance run的时候,是整个进程退出了...弹不出你的对话框是正常的...
但是里面的代码会运行....
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 eyey1 的回复:]
CSrcCappExtendedApp::InitInstance()里return TRUE;不要return FALSE试试。
[/Quote]


试了,没用。
VC6有关于InitInstance返回值注释的。
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 eyey1 的回复:]
AfxMessageBox的问题吧,帮你试了下,的确没弹出来,但设断点可以进去。
[/Quote]

断点怎么设置的,我设断点提示不行。基于视图的工程都是可以正常跳对话框出来的。奇怪。
手机写程序 2011-01-25
  • 打赏
  • 举报
回复
CSrcCappExtendedApp::InitInstance()里return TRUE;不要return FALSE试试。
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 eyey1 的回复:]
AfxMessageBox的问题吧,帮你试了下,的确没弹出来,但设断点可以进去。
[/Quote]

不仅AfxMessageBox,所有WritePrivateProfileString函数都没起作用。
chichujn 2011-01-25
  • 打赏
  • 举报
回复
试了一下,好像以前所有对话框工程加了析构函数都是没用的。
手机写程序 2011-01-25
  • 打赏
  • 举报
回复
AfxMessageBox的问题吧,帮你试了下,的确没弹出来,但设断点可以进去。
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lsupper 的回复:]
正常退出,还是强制杀进程?
[/Quote]

正常退出。。。
lsupper 2011-01-25
  • 打赏
  • 举报
回复
正常退出,还是强制杀进程?
sanic305 2011-01-25
  • 打赏
  • 举报
回复
一个帐号只能回复三次,囧。

问题找到了,原因是Dialog的析构函数没执行。把Dialog的一些delete的工作放到OnDestroy里,app析构函数正常工作了。

不过。新问题是,为什么Dialog的析构函数不管用。唉。
chichujn 2011-01-25
  • 打赏
  • 举报
回复
嗯,找到一点原因了。囧
chichujn 2011-01-25
  • 打赏
  • 举报
回复
CSrcCappExtendedApp::CSrcCappExtendedApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance

AfxMessageBox(_T("construction"));
}

CSrcCappExtendedApp::~CSrcCappExtendedApp()
{
AfxMessageBox(_T("destruction"));
}

//
运行前弹出对话框construction,关闭后不弹出destruction,匪夷所思。
chichujn 2011-01-25
  • 打赏
  • 举报
回复
回13楼,14楼。
/*************************/
BOOL CSrcCappExtendedApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CSrcCappExtendedDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return TRUE;
}

int CSrcCappExtendedApp::ExitInstance()
{
AfxMessageBox(_T(""));
return CWinApp::ExitInstance();
}

改成这样也完全不起作用。

另外,为什么析构函数没执行?这是最主要的。
  • 打赏
  • 举报
回复
我将初始化中的return false;
改为return true;
然后在ExitInstance进行测试是可以之行的
如果return false 就退出了消息泵
所以ExitInstance是执行不到的
在我这里是成功的
你妹的特盗不 2011-01-25
  • 打赏
  • 举报
回复
干嘛要在那里加呢?对话框程序有个 ExitInstance
这个是虚函数,在这个里面加需要的代码,程序退出的时候,会RUN到这里
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 schlafenhamster 的回复:]
可能与这2句有关:
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
Se……
[/Quote]

这是基于文档视图的工程app的InitInstance里的吧?对话框里是没有的。
复制到对话框app的InitInstance里也没用。
主要情况是,对话框IDOK结束了,不调用app的析构函数?怎么也说不过去啊。
schlafenhamster 2011-01-25
  • 打赏
  • 举报
回复
可能与这2句有关:
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
chichujn 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wwgddx 的回复:]
不用放到析构里面,放到 ExitInstance里看看
[/Quote]

问题依旧,邪门了。
wwgddx 2011-01-25
  • 打赏
  • 举报
回复
不用放到析构里面,放到 ExitInstance里看看

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧