|
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales
Call center available M-F 9:00 - 6:00 US Eastern Time. U.S. and Canada International Email |
Remove the close button from a floating toolbar
Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC
Downloads:
You can remove the close button from a floating toolbar by extending the CToolBar class and overriding the ON_WM_WINDOWPOSCHANGED message handler. This message handler is called whenever the size, position or Z order has changed for the CToolBar. We don't use the WM_SIZE message handler because it is only called when the size alone has changed and may not get called every time we float the toolbar. Also, we can take advantage of m_pDockBar from the CControlBar base class rather than making a call to GetParent() to get the parent frame of the toolbar. Derive a class from CToolBar, I called this class CToolBarEx, but you can choose one that suits your needs. 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 new class:
BOOL m_bMenuRemoved; This will get set to TRUE when we remove the system menu, ensuring that we only remove the system menu
when needed.
#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; } } |
