CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Guest

    Catching OnClose message for CDialogBar

    I'm trying to catch a WM_CLOSE or WM_DESTROY message for a control bar, but
    something is not right.
    I have a class MyClass that inherits from CDialogBar. An instance of MyClass is created in a class CMainFrame that inherits from CMDIFrameWnd. The control bar is than created using CDialogBar's Create member function. ShowControlBar()
    is also called to display the bar.


    My class has the following message map, with the OnClose()hook implemented.

    BEGIN_MESSAGE_MAP(CMyClass, CDialogBar)
    ON_WM_CLOSE()
    END_MESSAGE_MAP()

    Since CDialogBar inherits from CWnd, one would expet that catching the WM_CLOSE
    would work.
    For some reason OnClose() is never called. Help!!!



  2. #2
    Join Date
    May 1999
    Posts
    11

    Re: Catching OnClose message for CDialogBar

    You must overide the CDialog::OnCancel().
    just like this:

    void CMyDialog::OnCancel()
    {
    //Do something.
    CDialog::OnCancel();
    }





  3. #3
    Join Date
    May 1999
    Posts
    40

    Re: Catching OnClose message for CDialogBar

    The reason that you don't get the WM_CLOSE message is that the CDialogBar object doesn't get a close message. It is the parent window of the CDialogBar that gets the WM_CLOSE. The parent is a CMiniFrameWnd when the dialog bar is floating and something else when it is docked. When the parent gets the WM_CLOSE message it actually hides the dialog bar window. You can catch the hide message by handling the WM_WINDOWPOSCHANGED message. To do this add ON_WM_WINDOWPOSCHANGED() to the message map of your CDialogBar derived class and add the following method:


    afx_msg void OnWindowPosChanged( WINDOWPOS* lpwndpos );





    void CMyDialogBar::OnWindowPosChanged( WINDOWPOS* lpwndpos )
    {
    if (lpwndpos->flags & SWP_HIDEWINDOW)
    {
    // Add code to handle DialogBar close here.
    }
    CDialogBar::OnWindowPosChanged(lpwndpos);
    }




    OnWindowPosChanged is called not only to show/hide the window but alos to move it so you need to check the flags passed in to make sure it is really a window hide.



  4. #4
    Guest

    Re: Catching OnClose message for CDialogBar

    I tried what you said, but it didn't work. Note that my class inherits from CDialogBar, not CDialog. I used Spy++ to view messages that are sent to my
    Control bar upon clicking on the close button. No WM_CLOSE, WM_DESTROY, etc
    messages are sent to this window.


  5. #5
    Guest

    Re: Catching OnClose message for CDialogBar

    Josh Handley,
    Your reply was excellent, I never would of thought of that. However I'm now encountering another problem. I need to distinguish between when the Control bar is being docked vs closed. The SWP_HIDEWINDOW flag seems to be set in both cases. I tried using CDialogBar's IsFloating(), but it didn't work because the Control bar is still floating when I'm processing the WM_WINDOWPOSCHANGED() message.
    The whole purpose of this is the press or depress a button on a toolbar depending on the state of the CDialog bar.







  6. #6
    Join Date
    May 1999
    Posts
    40

    Re: Catching OnClose message for CDialogBar

    I see the problem. In my app the dialog bar is undockable so I didn't run into this. If you look in the MFC source code for CDockBar:ockControlBar (in BARDOCK.CPP) you will see where it calls SetWindowPos to hide the control bar before it starts to dock it. It does this to avoid flashing while it changes the control bar window.

    Instead of calling IsFloating you could try looking at the control bar style to see if the CBRS_FLOATING is set by calling GetBarStyle(). CDockBar:ockControlBar changes this flag just before it hides the window.

    Hope this helps,

    Josh


  7. #7
    Join Date
    May 1999
    Posts
    11

    Re: Catching OnClose message for CDialogBar

    if you want to close a dialog bar,you can use
    CDialogBar:estroyWindow() from any where you want.Because the dialog bar is not a dialog,
    so when you click the close button,no WM_CLOSE,and
    WM_DESTROY messages are sent to this window(Because no any function is called after you click this button!),You must add a function to handle this click message come from close button,and use DestroyWindow(...)to destroy this window.



  8. #8
    Guest

    Re: Catching OnClose message for CDialogBar

    Josh Handley,

    You've been very helpfull so I thought I'd ask you one more quick little question. Prior to me calling ShowControlBar() I want to disable the WM_WINDOWPOSCHANGED message temporarilly for my CDialogBar, and then re-enable it in an OnTimer(). How do I do this?
    This is were I am....



    // Initialize dialog bar m_wndGraphicsLegend
    //
    if (!m_wndGraphicsLegend.Create(this, CG_IDD_GRAPHICSLEGEND,
    CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
    CG_ID_VIEW_GRAPHICSLEGEND))
    {
    TRACE0("Failed to create dialog bar m_wndGraphicsLegend\n");
    return;
    }

    m_wndGraphicsLegend.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndGraphicsLegend);

    //
    // I want to disable the WM_WINDOWPOSCHANGED message here.....
    //

    ShowControlBar(&m_wndGraphicsLegend, FALSE, FALSE);
    SetTimer(1,200,NULL)
    }

    void CMainFrame::OnTimer(UINT nIDEvent)
    {
    KillTimer(1);

    //
    // Re-enable the WM_WINDOWPOSCHANGED message for m_wndGraphicsLegend
    //


    }










  9. #9
    Join Date
    May 1999
    Posts
    40

    Re: Catching OnClose message for CDialogBar

    I don't know of a way to stop your dialog bar from receiving the message. Wouldn't the simplest thing be just to set a flag in your dialog bar before you call ShowControlBar, check this flag in your handler for WM_WINDOWPOSCHANGED and then clear the flag in the OnTimer?


  10. #10
    Guest

    Re: Catching OnClose message for CDialogBar

    Josh,
    Once again thank you for your help. I just thought that maybe there was a neat way to disable the message. I did implement the flag method already...



  11. #11
    Join Date
    Mar 2012
    Posts
    7

    Re: Catching OnClose message for CDialogBar

    Quote Originally Posted by Josh Handley View Post
    I see the problem. In my app the dialog bar is undockable so I didn't run into this. If you look in the MFC source code for CDockBar:ockControlBar (in BARDOCK.CPP) you will see where it calls SetWindowPos to hide the control bar before it starts to dock it. It does this to avoid flashing while it changes the control bar window.
    And can you tell how to make undockable dialog bar? I want to dock it to the top of window in the code, and after that how can I make it impossible to dock-undock it with the mouse when app is running?

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Catching OnClose message for CDialogBar

    Victor Nijegorodov

  13. #13
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Catching OnClose message for CDialogBar

    Quote Originally Posted by Oleksii View Post
    And can you tell how to make undockable dialog bar? I want to dock it to the top of window in the code, and after that how can I make it impossible to dock-undock it with the mouse when app is running?
    It would be better to start a new thread for your question rather than reviving a thread that's 13 years old!
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

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