Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

When a toolbar floats, the MFC framework normally supplies a window menu (formerly known as system menu) to the toolbar. The toolbar can be floated by a double click or by dragging it to the center of the screen. This code demonstrates how to do it.

Note: I could not get the mini frame window to repaint. So I had to first hide and then show the toolbar to achieve the same effect. I tried UpdateWindow, SetWindowPos, MoveWindow etc. Suggestions welcome.

1. Derive your own toolbar CMyToolBar from CToolBar and update the m_wndToolBar member in the main frame.

2. In CMyToolBar::OnLButtonDblClk(...), add the following:

	CToolBar::OnLButtonDblClk(...); //fill the parameters 

	if (IsFloating()) //is toolbar floating
		CWnd* pMiniFrame;
		CWnd* pDockBar;

		pDockBar = GetParent();
		pMiniFrame = pDockBar->GetParent();

		//get rid of window menu
		pMiniFrame->ModifyStyle(WS_SYSMENU, NULL);

		//extreme way of re-painting the toolbar

3. Repeat same code in OnLButtonDown(...) and elsewhere.


  • Another way to update miniframe (and any other window at all)

    Posted by Scrambler on 08/06/2004 01:21pm

    I want to suggest you a better way to redraw a window. I'm always using this method in my apps. pMiniFrame->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME);

  • The CORRECT way to repaint miniframe window

    Posted by Legacy on 12/01/2002 08:00am

    Originally posted by: Lord KiRon

  • Remove system menu from floating toolbar

    Posted by Legacy on 07/12/2002 07:00am

    Originally posted by: Arie

    There is another approtch to leave the system menu but disable the toolbar from closing using the DelayShow virtual function in the CControlBar

    in the controll toolbar there is a function
    class CMyToolBat : public CToolBar
    virtual void DelayShow(BOOL bShow);

    U can overwrite the function and return nothing

    void CMyToolBat::DelayShow(BOOL bShow)

    or set the value of bShow to 1 i.e display always never hide.

    void CMyToolBat::DelayShow(BOOL bShow)
    bShow = 1 ;
    CControlBar::DelayShow(bShow) ;

    The normal operation is

    void CMyToolBat::DelayShow(BOOL bShow)
    CControlBar::DelayShow(bShow) ;

    I hope that this approtch also acceptable altough the close icon appears but does nothing.

  • Disable/Enable controls on toolbar.

    Posted by Legacy on 02/19/2002 08:00am

    Originally posted by: Nga Lin

    Please show me how to disable/enable the controls (such as button, combobox, etc.) in the toolbar of a single document application.
    Thank in advance.
    Nga Lin.

  • Repainting the mini-frame window

    Posted by Legacy on 09/17/2001 07:00am

    Originally posted by: Alex Letov

    I too was suffering from this problem and suggest the following:


    2.pMiniFrame->SendMessage( WM_NCPAINT, 1, 0 );

  • A more efficient approach might be...

    Posted by Legacy on 01/18/2000 08:00am

    Originally posted by: Kirk Stowell

    A more efficient approach might be to override the ON_WM_WINDOWPOSCHANGED 
    message handler. This message handler is called whenever the size, position
    or Z order has changed for the CToolBar where the WM_SIZE message is only
    called when the size alone has changed, and may not get called every time
    we float the toolbar.

    Additionally, we might as well take advantage of m_pDockBar from the CControlBar
    base class rather than making a call to GetParent() we can use this member to
    get the parent frame of the toolbar. Derive a class from CToolBar, I called this
    one CXToolBar.

    We only need to remove the close button when the toolbar is floating, so check to
    see if the bar is actually floating, making sure that m_pDockBar is a valid pointer.

    Add this member variable to your class:

    BOOL m_bMenuRemoved;

    This will get to TRUE when we remove the system menu, ensuring that we only remove
    the system menu when needed.

    We will then need to get a pointer to the parent of m_pDockBar to check to see if
    it is indeed a CDockFrameWnd class so, we can safely remove the system menu from
    the CToolBar.

    And here is the code:

    // CXToolBar message handlers

    #include <afxpriv.h>

    void CXToolBar::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)

    // should only be called once, when floated.
    if( IsFloating() )
    if( m_pDockBar && !m_bMenuRemoved )
    CWnd* pParent = m_pDockBar->GetParent();
    if( pParent->IsKindOf(RUNTIME_CLASS(CMiniFrameWnd)))
    pParent->ModifyStyle( WS_SYSMENU, 0, 0 );
    m_bMenuRemoved = TRUE;
    else if( m_bMenuRemoved ) {
    m_bMenuRemoved = FALSE;

    Hope this helps, happy coding!
    -- Kirk

  • Repainting the mini frame window

    Posted by Legacy on 12/30/1999 08:00am

    Originally posted by: Mark Freeman

    I too was suffering from this problem and was having little success with ShowWindow. In my case I was just trying to get a floating toolbar to reappear if the user closed it via the 'X' on the mini frame.

    To do this, call the ShowControlbar method of CMiniFrameWindow instead of ShowWindow and it seems to repaint itself correctly.

    // pMiniFrame->ShowWindow(SW_HIDE);
    // pMiniFrame->ShowWindow(SW_SHOW);


  • Repainting a mini-frame window

    Posted by Legacy on 05/28/1999 07:00am

    Originally posted by: Marcus Breese

    I was having a similar problem with creating a tool window.
    It seems that if you move the window, then SetWindowPos / ModifyStyleEx it, it will repaint properly.


    This function will create a floating tool window that stays "Always on Top" without a system menu (I'd advise putting that back though...) :)

    void CMainFrame::MakeFloat()
    CRect rect;
    SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top,rect.Width(),rect.Height(),WS_EX_TOPMOST);
    ModifyStyle(WS_SYSMENU, NULL);


  • DoubleClick is not captured by the Derived Toolbar class

    Posted by Legacy on 04/08/1999 07:00am

    Originally posted by: Simon Pettman


    In my app when I implemented this the double click handler did not even get called and the tool bar just jumped back into the docking area.

    I put a RecalcLayout in the CMainFrame :-
    void CMainFrame::RecalcLayout(BOOL bNotify)
    // TODO: Add your specialized code here and/or call the base class

    CWnd* pMiniFrame;
    CWnd* pDockBar;

    pDockBar = m_wndToolBar2.GetParent();
    pMiniFrame = pDockBar->GetParent();

    //get rid of window menu
    pMiniFrame->ModifyStyle(WS_SYSMENU, NULL);

    //extreme way of re-painting the toolbar
    // pMiniFrame->ShowWindow(SW_HIDE);
    // pMiniFrame->ShowWindow(SW_SHOW);


    And it worked.

    Thanks I have been banging my head about this one.

    Simon Pettman

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date