Answer the question
In order to leave comments, you need to log in
WinAPI :: What happens when you close a program in Windows?
Welcome all!
I am studying WinAPI, the moment of closing the program became interesting, that is, the release of a message WM_DESTROY
. I can not understand the next point, I will try to explain:
When I click on the cross in the upper area of \u200b\u200bthe window (or Alt + F4), Windows, my program sends a message WM_DESTROY
while itself (Windows) hides my window.
I thought, what if by rejecting the message WM_DESTROY
, do not exit the program and display the window again.
When processing a message, the following code stands:
case WM_DESTROY :
if (MessageBox(hwnd, "Пришла просьба закрыться!","!!!", MB_OKCANCEL) == IDOK )
{
PostQuitMessage(0) ;
}
else
{
ShowWindow(hwnd, SW_NORMAL);
}
return 0 ;
Answer the question
In order to leave comments, you need to log in
Use the WM_CLOSE event handling to prevent the window from closing.
wm_destroy is just a request to the application to close the window (not the application)
according to the unwritten ui rules, in windows, after closing the last application window (there may be several), the application itself must be closed.
In your case, when canceling, it is necessary to return in return it seems true (look at the documentation) by this you will tell the calling function that the process has changed its mind about closing the window and will not delete it. I vaguely remember that you had to call some other method before return - the window's event handler by default, just when canceling the closing it will not need to be called.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question