在Windows程序中WM_QUIT,WM_CLOSE和WM_DESTROY之间有什么区别? [英] What is the difference between WM_QUIT, WM_CLOSE, and WM_DESTROY in a windows program?
问题描述
我想知道在Windows程序中的WM_QUIT,WM_CLOSE和WM_DESTROY消息之间的区别本质上是:他们发送什么时候,除了程序定义的东西之外,他们有什么自动效果吗?
$ b WM_CLOSE $ c当按下X或从窗口菜单中选择关闭时,$ c>发送到窗口。如果你抓住这个消息,这是你的电话如何对待它 - 忽略它或真正关闭窗口。默认情况下,
WM_CLOSE
传递给 DefWindowProc
原因窗口被销毁。当窗口被销毁时,发送 WM_DESTROY
消息。在这个阶段,与 WM_CLOSE
相反,你不能停止进程,你只能进行必要的清理。但请记住,当你在所有子窗口已经被销毁之前捕获 WM_DESTROY
。 WM_NCDESTROY
是在所有子窗口被销毁后发送的。
WM_QUIT
消息与任何窗口无关( hwnd
从获取GetMessage
为NULL并且没有窗口过程称为)。此消息指示应停止消息循环,并应关闭应用程序。当 GetMessage
读取 WM_QUIT
时,它返回0以指示。查看典型的邮件循环代码段 - 循环继续,而 GetMessage
返回非零。 WM_QUIT
可以通过 PostQuitMessage
函数发送。此函数通常在主窗口接收 WM_DESTROY
时调用(请参阅典型的窗口过程片段)。
I was wondering what the difference between the WM_QUIT, WM_CLOSE, and WM_DESTROY messages in a windows program, essentially: when are they sent, and do they have any automatic effects besides what's defined by the program?
They are totally different.
WM_CLOSE
is sent to the window when "X" is pressed or "Close" is chosen from window menu. If you catch this message this is your call how to treat it - ignore it or really close the window. By default, WM_CLOSE
passed to DefWindowProc
causes window to be destroyed. When the window is being destroyed WM_DESTROY
message is sent. In this stage, in opposition toWM_CLOSE
, you cannot stop the process, you can only make a necessary cleanup. But remember that when you catch WM_DESTROY
just before all child windows are already destroyed. WM_NCDESTROY
is send just after all child windows have been destroyed.
WM_QUIT
message is not related to any window (the hwnd
got from GetMessage
is NULL and no window procedure is called). This message indicates that the message loop should be stopped and application should be closed. When GetMessage
reads WM_QUIT
it returns 0 to indicate that. Take a look at typical message loop snippet - the loop is continued while GetMessage
returns non-zero. WM_QUIT
can be sent by PostQuitMessage
function. This function is usually called when main window receives WM_DESTROY
(see typical window procedure snippet).
这篇关于在Windows程序中WM_QUIT,WM_CLOSE和WM_DESTROY之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!