-
June 29th, 2016, 12:51 PM
#1
[RESOLVED] PostQuitMessage: why the WM_DESTROY isn't called?
heres my message loop:
Code:
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents,NULL,0,0))
{
if(!IsDialogMessage(ActivatedForm,&msgEvents))
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
return msgEvents.wParam;
}
heres my End() function:
Code:
void End()
{
if(hhookCBTProc!=0)
UnhookWindowsHookEx(hhookCBTProc);
PostQuitMessage(0);
}
why, when i use the PostQuitMessage(), the WM_DESTROY isn't called?
what window message i can use after the PostQuitMessage()?
-
June 29th, 2016, 01:15 PM
#2
Re: PostQuitMessage: why the WM_DESTROY isn't called?
Originally Posted by Cambalinho
...
why, when i use the PostQuitMessage(), the WM_DESTROY isn't called?
what window message i can use after the PostQuitMessage()?
Because you are doing it the wrong way.
The correct way to close/exit the Windows GUI application is described in MSDN: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Victor Nijegorodov
-
June 29th, 2016, 01:37 PM
#3
Re: PostQuitMessage: why the WM_DESTROY isn't called?
i have 2 windows(forms).
1 call the End()(on menu click) and the other is the console window. but the WM_DESTROY isn't called, because, i belive, the message loop was closed.
so what you can tell me more?
-
June 29th, 2016, 01:43 PM
#4
Re: PostQuitMessage: why the WM_DESTROY isn't called?
even the class destructor(any class) seems been ignored.
-
June 29th, 2016, 01:53 PM
#5
Re: PostQuitMessage: why the WM_DESTROY isn't called?
Originally Posted by Cambalinho
...
so what you can tell me more?
Again, you must read the MSDN carefully to understand how to close windows application gracefully. I gave you a link in the post#2.
Victor Nijegorodov
-
June 29th, 2016, 01:54 PM
#6
Re: PostQuitMessage: why the WM_DESTROY isn't called?
Originally Posted by Cambalinho
even the class destructor(any class) seems been ignored.
It is because of the serious design and implementation bugs...
Victor Nijegorodov
-
June 29th, 2016, 02:57 PM
#7
Re: PostQuitMessage: why the WM_DESTROY isn't called?
when i use the PostQuitMessage(), the WM_DESTROY isn't called?
From MSDN
respond to WM_DESTROY by calling PostQuitMessage
As Victor has already explained, you call PostQuitMessage() from the WM_DESTROY message. PostQuitMessage doesn't generate a WM_DESTROY message. It indirectly terminates the message loop by posting a WM_QUIT message which when processed by the message loop will terminate the message loop.
even the class destructor(any class) seems been ignored.
A class destructor is called when a class instance goes out of scope. If a thread is 'terminated' - as opposed to being allowed to end gracefully, then destructors etc are not called. If you are finding that class destructors are not being called then you are not ending a thread correctly. Again, as both Victor and myself and stated, this is due to design issues.
Last edited by 2kaud; June 29th, 2016 at 03:02 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 29th, 2016, 03:02 PM
#8
Re: [RESOLVED] PostQuitMessage: why the WM_DESTROY isn't called?
thank you to both. thanks for correct me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|