Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relationship of CloseWindow and WM_CLOSE

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?

like image 526
Martin Ba Avatar asked Jun 18 '13 12:06

Martin Ba


People also ask

What is the purpose of WM destroy message?

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.

Do I need to call DestroyWindow?

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.


2 Answers

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.

like image 74
David Heffernan Avatar answered Sep 21 '22 16:09

David Heffernan


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().

like image 20
Hans Passant Avatar answered Sep 24 '22 16:09

Hans Passant