Difference between WM_CLOSE and SC_CLOSE

半世苍凉 提交于 2019-12-11 05:37:02

问题


I just want to know what is the difference between these two messaging constants. Which one should I use in WndProc method when overriding, to handle close button message.


回答1:


WM_CLOSE is sent as a window message whenever the window is requested to be closed, by any means.

SC_CLOSE is sent as a parameter of a WM_SYSCOMMAND message, when the user presses the Close button (or selects Close from the control menu of the window).

Which one you listen for is determined by which action(s) you attempting to intercept/deal with.




回答2:


According to msdn, SC_CLOSE is one of wParam values of WM_SYSCOMMAND message.

A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.

WM_CLOSE is a message itself.

Sent as a signal that a window or an application should terminate.

So, when window receives WM_SYSCOMMAND with parameter value SC_CLOSE, then you can close window (send WM_CLOSE message).

UPDATE (if you want to let user to close the window gracefully): An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.

BTW if you use C#, you can handle FormClosing event and do you work there. If you need to cancel closing, then just set e.Cancel = true for event argument.



来源:https://stackoverflow.com/questions/10101742/difference-between-wm-close-and-sc-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!