关于界面销毁的讨论
孟如庭 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).