Remove system menu from floating toolbar

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
		pMiniFrame->ShowWindow(SW_HIDE);
		pMiniFrame->ShowWindow(SW_SHOW);
	}

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



Comments

  • Beats headset alle omkring dig kan være en velkendt fænomen

    Posted by wanzixiao on 06/04/2013 01:08pm

    [url=http://www.beatsbydrdredanmark.moonfruit.com/]beats by dre danmark[/url] Dr. Dre er lykkedes gatecrashing London 2012 Olympics med et baghold marketing kampagne, der har set britiske sportsfolk, herunder Laura Robson og Tom Daley godkende rapper og musik iværksætterens Beats hovedtelefoner rækkevidde.Mærket, der ikke er officiel sponsor af Den Internationale Olympiske Komité eller London 2012, har skørt strenge regler for baghold markedsføring ved at sende britiske teammedlemmer særlige versioner af Beats spænder brandet med union flag farver.Tennisspiller Laura Robson tweeted om at modtage hendes hovedtelefoner, selvom stillingen nu synes at være blevet fjernet fra sin Twitter-konto , som gjorde fodbold målmand Jack Butland, som tweeted : “. Love My GB Beats by Dre” [url=http://www.kbhretelefonerbillig.webstarts.com/]Køb høretelefoner billig[/url] Beats hovedtelefoner har stor detalje, opløsning og billeddannelse. Når du vender kontakten til basforstærkning de er omtrent lige så god på den lave ende som enhver sammenligneligt prissat hovedtelefoner vi har hørt. Når du lytter til kvindelige vokal mere end guitar med støjreducerende på, hovedtelefonerne lyder stadig fuld og tilfredsstillende.Hvis han ikke havde travlt nok hjælpe Intel ud, musik kunstner og producer nu hjælpe miljøet ved at samarbejde med Coca-Cola og Beats med lanceringen af EKOCYCLE. Denne stand-alone initiativ er dedikeret til at fremme genbrug gennem produkter fremstillet i en del af genbrugsmateriale. Dybest set ønsker dig til at tænke genbrug er lige så cool som en iført et par beats hovedtelefoner, eller drikke en dåse cola. [url=http://www.nyebeatsbydrdre.350.com/]beats by dre danmark[/url] Dr. Dre er lykkedes gatecrashing London 2012 Olympics med et baghold marketing kampagne, der har set britiske sportsfolk, herunder Laura Robson og Tom Daley godkende rapper og musik iværksætterens Beats hovedtelefoner rækkevidde.Mærket, der ikke er officiel sponsor af Den Internationale Olympiske Komité eller London 2012, har skørt strenge regler for baghold markedsføring ved at sende britiske teammedlemmer særlige versioner af Beats spænder brandet med union flag farver.Tennisspiller Laura Robson tweeted om at modtage hendes hovedtelefoner, selvom stillingen nu synes at være blevet fjernet fra sin Twitter-konto , som gjorde fodbold målmand Jack Butland, som tweeted : “. Love My GB Beats by Dre”

    Reply
  • Nike Draught Max+instagram, will you confine the color to bear up on your feet!

    Posted by madytreathy on 04/19/2013 02:53am

    Recognize in 2008, if not earlier, when Nike launched up ahead of the independent shoe color projects, the watchword "Shoot Your Colours", "Nike PhotoiD" arrangement, [url=http://northernroofing.co.uk/roofins.cfm]nike free run[/url] response has not been as fervent as expected. Think, 2008 Canon IXUS 80 IS Digital prankster arcade but contrariwise 8 million pixels, Nokia, the motorized phone superstore is the one leadership, NikeiD was promote to color in the photos as a essence someone is concerned sneakers levy color, although exciting, but does trouble some. Instagram which make this thing make sport and elemental, Nike PHOTOiD homeopathic upgrade customization services, recently [url=http://northernroofing.co.uk/roofins.cfm]nike free run uk[/url] released a fresh plan. That such iD can you implement pictures as instagram account shoe color, for a short put up Nike Aura Max shoes and Nike Refresh Max 1, Nike Air Max 90 953 options. Interested in children's shoes, you [url=http://northernroofing.co.uk/roofins.cfm]nike free run 3[/url] can without exception go's official website photoid.Nike.com, in addition to skim through other people's ingenious charge, or you can try to upload your own instagram photo, build your own Nike Hauteur Max.

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

    Posted by Scrambler on 08/06/2004 06:21am

    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);

    Reply
  • The CORRECT way to repaint miniframe window

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

    Originally posted by: Lord KiRon

    Reply
  • Remove system menu from floating toolbar

    Posted by Legacy on 07/12/2002 12: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
    {
    .....
    public:
    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.

    Reply
  • Disable/Enable controls on toolbar.

    Posted by Legacy on 02/19/2002 12: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.

    Reply
  • Repainting the mini-frame window

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

    Originally posted by: Alex Letov

    I too was suffering from this problem and suggest the following:
    1. pMiniFrame->RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME );

    or

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

    Reply
  • A more efficient approach might be...

    Posted by Legacy on 01/18/2000 12: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)
    {
    CToolBar::OnWindowPosChanged(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


    Reply
  • Repainting the mini frame window

    Posted by Legacy on 12/30/1999 12: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);

    pMiniFrame->ShowControlBar((CControlBar*)this,TRUE,FALSE);

    Reply
  • Repainting a mini-frame window

    Posted by Legacy on 05/28/1999 12: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.

    i.e.

    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;
    GetWindowRect(rect);
    MoveWindow(rect);
    SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top,rect.Width(),rect.Height(),WS_EX_TOPMOST);
    ModifyStyle(WS_SYSMENU, NULL);
    ModifyStyleEx(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE,WS_EX_TOOLWINDOW, TRUE);

    }

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds