CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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()?

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: PostQuitMessage: why the WM_DESTROY isn't called?

    Quote Originally Posted by Cambalinho View Post
    ...
    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

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    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?

  4. #4
    Join Date
    Apr 2009
    Posts
    1,355

    Re: PostQuitMessage: why the WM_DESTROY isn't called?

    even the class destructor(any class) seems been ignored.

  5. #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: PostQuitMessage: why the WM_DESTROY isn't called?

    Quote Originally Posted by Cambalinho View Post
    ...
    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

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: PostQuitMessage: why the WM_DESTROY isn't called?

    Quote Originally Posted by Cambalinho View Post
    even the class destructor(any class) seems been ignored.
    It is because of the serious design and implementation bugs...
    Victor Nijegorodov

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    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)

  8. #8
    Join Date
    Apr 2009
    Posts
    1,355

    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
  •  





Click Here to Expand Forum to Full Width

Featured