关于界面销毁的讨论

孟如庭 2015-05-06 10:30:25
大家先看看这个贴。http://bbs.csdn.net/topics/390898180

后来我在MSDN看到EndDialog 明确提到不是立即销毁,DestroyWindow 是发消息,意思也是会等一段时间。

今天,我又遇到了一种情况,应该是和上述现象本质原因是一样的。还是在一个DLL库中显示不同的DLG,用于不同的信息提示,有模态,有非模态。具体现象是:
模态显示一个对话框A的时候(DialogBoxParam调用,窗口函数中通过EndDialog 销毁),第二次调用DialogBoxParam很大概率出错,直接返回-1,LastError是183(错误意义是:当文件已存在时,无法创建该文件)

我个人的感觉就是第一次DialogBoxParam对话框A的时候,调用EndDialog 销毁,系统实际还没有销毁,然后第二次DialogBoxParam对话框A,就报错183了

关于这种现象,大家遇到过吗,有解决方法吗?


以下是MSDN解释。
EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.

The DestroyWindow function destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).
...全文
199 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2015-06-13
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
孟如庭 2015-05-11
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
DialogBoxParam 是模态形式的 按理应该返回时窗口就已经销毁了的 可以单步跟踪进去看看问题在哪一步 或者向导生成一个简单的程序测试试试看
这个错误,在调试上是无法出现了。我加log,也没出现,怀疑是我写文件时buff开的太大,我开了个4k的buf。后来开了小的buffer,一步步添加log才看到的错误情况
zgl7903 2015-05-08
  • 打赏
  • 举报
回复
DialogBoxParam 是模态形式的 按理应该返回时窗口就已经销毁了的 可以单步跟踪进去看看问题在哪一步 或者向导生成一个简单的程序测试试试看
Eleven 2015-05-08
  • 打赏
  • 举报
回复
EndDialog应该没有问题。 When the dialog box procedure calls the EndDialog function, DialogBoxParam destroys the dialog box, ends the message loop, enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it called EndDialog.

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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