Click here to Skip to main content
15,916,030 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionwhat about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
xqhrs23224-Apr-08 23:13
xqhrs23224-Apr-08 23:13 
AnswerRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
Rajkumar R25-Apr-08 0:50
Rajkumar R25-Apr-08 0:50 
AnswerRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
David Crow25-Apr-08 3:08
David Crow25-Apr-08 3:08 
GeneralRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
Michael Schubert25-Apr-08 4:30
Michael Schubert25-Apr-08 4:30 
GeneralRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
David Crow25-Apr-08 4:40
David Crow25-Apr-08 4:40 
GeneralRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
Michael Schubert25-Apr-08 4:50
Michael Schubert25-Apr-08 4:50 
GeneralRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? Pin
Nelek27-Apr-08 1:45
protectorNelek27-Apr-08 1:45 
AnswerRe: what about WM_CLOSE ,WM_DESTROY and WM_QUIT? PinPopular
Mike Dimmick25-Apr-08 4:28
Mike Dimmick25-Apr-08 4:28 
You use WM_CLOSE to ask a window to close itself. This gives it a chance to ask the user whether to save documents, etc. The default handling (by DefWindowProc) is to call DestroyWindow.

You never send WM_DESTROY yourself. It is sent to the window by the DestroyWindow function to allow it to do some final cleanup.

On desktop Windows (i.e. not on Windows CE) there is also a WM_NCDESTROY message which is sent after WM_DESTROY, when the non-client area is destroyed. This will be the last message ever for that window and can be handled for final final cleanup Wink | ;)

WM_QUIT isn't really a window message at all. It's a status flag in the message queue which is set when PostQuitMessage has been called. You should never send WM_QUIT. Its sole purpose is to get GetMessage to return 0. Once the quit message has been retrieved the status flag is cleared, so if you've created a nested message loop you should call PostQuitMessage again to cause the next message loop in the chain to quit as well. MFC and ATL call PostQuitMessage after handling WM_NCDESTROY on the thread's main window (that pointed to by CWinThread::m_pMainWnd in the case of MFC). See Raymond Chen's blog entries on WM_QUIT[^] and PostQuitMessage[^].

If you're coding it yourself using just the Win32 SDK, you normally call PostQuitMessage in response to receiving a WM_DESTROY message. You only have to handle WM_CLOSE yourself if you want to interrupt and potentially prevent the window from closing, as long as you're passing everything you don't handle down to DefWindowProc. (No, really, you need to pass all unhandled messages to DefWindowProc[^].)


DoEvents: Generating unexpected recursion since 1991

GeneralSystem Security Center Pin
Jangid24-Apr-08 22:55
Jangid24-Apr-08 22:55 
GeneralCopy file issue Pin
VCsamir24-Apr-08 21:59
VCsamir24-Apr-08 21:59 
GeneralRe: Copy file issue Pin
CPallini24-Apr-08 22:57
mveCPallini24-Apr-08 22:57 
GeneralRe: Copy file issue Pin
Hamid_RT25-Apr-08 3:09
Hamid_RT25-Apr-08 3:09 
QuestionCreateProcessWithLogonW Pin
Ajay L D24-Apr-08 21:29
Ajay L D24-Apr-08 21:29 
GeneralRe: CreateProcessWithLogonW Pin
Rajkumar R24-Apr-08 22:17
Rajkumar R24-Apr-08 22:17 
GeneralRe: CreateProcessWithLogonW Pin
Ajay L D24-Apr-08 22:41
Ajay L D24-Apr-08 22:41 
GeneralRe: CreateProcessWithLogonW Pin
Rajkumar R24-Apr-08 22:57
Rajkumar R24-Apr-08 22:57 
RantRe: CreateProcessWithLogonW Pin
Rajkumar R24-Apr-08 22:45
Rajkumar R24-Apr-08 22:45 
GeneralRe: CreateProcessWithLogonW Pin
Ajay L D25-Apr-08 0:07
Ajay L D25-Apr-08 0:07 
GeneralRe: CreateProcessWithLogonW Pin
Ajay L D25-Apr-08 0:18
Ajay L D25-Apr-08 0:18 
GeneralRe: CreateProcessWithLogonW Pin
Rajkumar R25-Apr-08 0:30
Rajkumar R25-Apr-08 0:30 
GeneralRe: CreateProcessWithLogonW Pin
Ajay L D25-Apr-08 3:33
Ajay L D25-Apr-08 3:33 
QuestionDetours and SetWindowsHookEx question [modified] Pin
yonghengzhimi24-Apr-08 21:28
yonghengzhimi24-Apr-08 21:28 
GeneralRe: Detours and SetWindowsHookEx question Pin
Nitheesh George24-Apr-08 22:47
Nitheesh George24-Apr-08 22:47 
GeneralRe: Detours and SetWindowsHookEx question [modified] Pin
yonghengzhimi24-Apr-08 23:51
yonghengzhimi24-Apr-08 23:51 
GeneralRe: Detours and SetWindowsHookEx question Pin
Nitheesh George29-Apr-08 22:53
Nitheesh George29-Apr-08 22:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.