多窗口程序
我读了很多关于这个主题的文章,其中一些在 stackoverflow 上,但没有人问我的问题。我会尝试具体一点。
我需要创建一个带有主窗口(窗口类“a”)的应用程序(本机 WinAPI)。当用户单击那里的按钮时,会弹出一个“b”类窗口。它可能是模态的,也可能不是模态的,我现在不在乎。
我尝试制作一个具有两个窗口类和两个窗口过程的应用程序。但问题是,当我关闭第二个窗口时,整个应用程序都会关闭。
谢谢。
I read many articles on the topic, a few of them were here, on stackoverflow, but none of them asked my question. I'll try to be specific.
I need to create an application (native WinAPI) with a main window (of window class "a"). When the user clicks a button there, a window of "b" class pops up. It might be modal or not, I don't care right now.
I tried making an application with two window classes and two window procedures. But the problem is that when I close the second window, the whole application shuts down.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据猜测,第二个窗口的窗口过程基于主窗口的窗口过程,因此当它收到
WM_DESTROY
时,它会调用PostQuitMessage
。这对于顶级窗口来说是正常的,因为用户期望销毁它就意味着退出应用程序。对于子窗口(模态窗口或其他窗口)而言,情况并非如此,因此子窗口不应该(同样,正常情况下)在其WM_DESTROY
PostQuitMessage > 处理程序。At a guess, the window procedure for your second window is based on one for a main window, so when it receives a
WM_DESTROY
, it's callingPostQuitMessage
. This is normal for the top-level window, because the user expects destroying it to mean exiting the application. For a child window (modal or otherwise) that's not the case though, so the child should not (again, normally) callPostQuitMessage
in itsWM_DESTROY
handler.