I'm a bit confused currently: Are WM_CLOSE and ::CloseWindow
in any way "related" or are for completely different things?
The docs for Closing Windows don't mention the API function CloseWindow
at all. Should CloseWindow
be really called "MinimizeWindow" or what am I missing?
It is sent to the window procedure of the window being destroyed after the window is removed from the screen. This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. During the processing of the message, it can be assumed that all child windows still exist.
If you really do want to close the window, call the DestroyWindow function. Otherwise, simply return zero from the WM_CLOSE message, and the operating system will ignore the message and not destroy the window.
CloseWindow
and WM_CLOSE
are completely unrelated. The CloseWindow
function is badly named. Its inverse function, OpenWindow
is similarly badly named given that it restores windows.
I suspect these names dates back a very long way indeed, probably to Windows version 1 or 2. I'm speculating that what we now call minimize and restore were, back then, called close and open.
The usual way to minimize or restore a window is to call ShowWindow
passing SW_MINIMIZE
or SW_RESTORE
.
I suggest that you forget all about CloseWindow
and OpenWindow
.
CloseWindow
is an unusually poorly named winapi function. It doesn't actually close a window, it just minimizes it. What you possibly meant was DestroyWindow()
.
WM_CLOSE
is normally a message that's generated by default window procedure, in response to the user pressing Alt+F4 or clicking the window's close button. The underlying message is WM_SYSCOMMAND
, SC_CLOSE
. It can be generated in code as well, like a Window + Close menu item.
You can listen for WM_CLOSE
in your window procedure or the MFC message map. The user will expect the window to be closed. So you normally call DestroyWindow()
. You don't have to, you might display a message box for example and ask the user if data should be saved. And if he clicks No then you don't call DestroyWindow()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With