For example, let's say I want to make 2 buttons, a button displays a few windows when clicked and so when you click another button those few windows close and other different few windows appear. Is that possible? I have thought of a way but it would take too much time.
Sure. With CreateWindow() one can create one or more windows of whatever Window Class is specified as a function call parameter. The DestroyWindow() call can destroy whichever of those windows are specified as a parameter. Any of these actions can be the result of a button click.
Likely you'll want a 'main' window with button child window controls. The registration of the main window will be in WinMain(). In the WM_CREATE handler for the main window do the registrations for whatever other Window Classes you'll need. In the WM_COMMAND handler you''ll create or destroy windows as you like in response to button clicks. I likely have an example of this posted somewhere. I can look if you like.
As far as I recall, WM_CLOSE only sends a prompt, if a messagebox routine has been placed in the WM_DESTROY case. The most common use of the involves a file-save flag---"Do you wish to save before exiting?", or something similar.
If a WM_CLOSE is sent, and there is no WM_CLOSE message handler, i.e., it is 'handled' by DefaultWindowProc(), then Windows sends either a WM_DESTROY message, or just calls DestroyWindow(). I forget which. Bottom line....if you want to code a MessageBox() to query the user for confirmation, then code a WM_CLOSE message handler.
I've personally never had a crash at program close out unless I fouled up my address space somewhere with pointer over runs or something like that. OF course, in OOP speak, the DestroyWindow() call is the Destructor Call.
Just checked.....From MS Docs....
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.
By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.
I added some code to your subclassing post anachronon. I'm not able to start a new topic on this forum. Haven't been able to for years. Not sure why. I think its punishment for various statements I've made over the years that I don't use the C++ part of the standard libraries in my work.
Most of the microsoft's pre-installed programs on windows do have a WM_CLOSE handler, so if you do it with some of those they will prompt upon the WM_CLOSE event.
However you can still check whether the window still exists or not using for example;
FindWindowA(NULL, (the old window title) );
and if it still exists, send another message, VK_RETURN which enters the prompt and closes the window.