Professional UI Solutions
Site Map   /  Register


Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » How to disable a toolbar button ownerdraw popup menu? Collapse All
Subject Author Date
Peter Meier Sep 23, 2008 - 10:28 AM


How can I disable the pulldown menu of the linewidth button in the DRAWCLI sample application? It pops up when I click on it although the button itself is disabled (i.e. when no object is selected).

Thanks - Peter

Technical Support Sep 24, 2008 - 4:53 AM

The CExtBarButton::CanBePressedInDisabledState() virtual method returns a flag which indicates whether disabled toolbar buttons are click-able. We have enabled mouse clicks and popup menu displaying from disabled toolbar buttons due to numerous customer requests. To disable this feature, you should use the following toolbar button class:

class CYourBarButton : public CExtBarButton
      DECLARE_DYNCREATE( CYourBarButton );
      CExtBarColorButton( CExtToolControlBar * pBar = NULL, UINT nCmdID = ID_SEPARATOR, UINT nStyle = 0 )
            : CExtBarButton( pBar, nCmdID, nStyle )
      virtual bool CanBePressedInDisabledState()
            ASSERT_VALID( this );
            if( IsDisabled() )
                  return false;
            return CExtBarButton::CanBePressedInDisabledState();

IMPLEMENT_DYNCREATE( CYourBarButton, CExtBarButton );
You will also need to create your CExtToolControlBar-derived class which implements the CExtToolControlBar::OnCreateBarCommandBtn() virtual method for instantiating instances the of your CExtToolControlBar class instead of CExtBarButton class:
CExtBarButton * CYourToolControlBar::OnCreateBarCommandBtn(
      UINT nCmdID,
      UINT nStyle // = 0
      ASSERT_VALID( this );
CExtBarButton * pTBB = new CYourBarButton( this, nCmdID, nStyle );
      return pTBB;
If you are using customizable toolbars, then you will also need to make customize site creating instances of the CYourToolControlBar toolbars. You should override the CExtCustomizeSite::OnUserBarCreate() virtual method:
virtual CExtToolControlBar * CExtCustomizeSite::OnUserBarCreate(
      __EXT_MFC_SAFE_LPCTSTR strName,
      UINT nBarID, // = 0 // 0-alloc any, other-alloc specified
      bool bCreateInvisible, // = false
      CExtToolControlBar * pBarNew // = NULL
      if( pBarNew == NULL )
            pBarNew = new CYourToolControlBar;
      return CExtCustomizeSite::OnUserBarCreate( strName, nBarID, bCreateInvisible, pBarNew );