Professional UI Solutions
Site Map   /  Register
 
 

Forum

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 General Discussion » Inserting a custom control in a toolbar Collapse All
Subject Author Date
Keith Degrace Jun 5, 2009 - 12:48 PM

The following pseudo code inserts a custom control in a non customizable toolbar.  Is it possible to accomplish the same thing with a customizable toolbar (i.e. using CExtCustomizeCmdTreeNode)?  If so, can you please provide some details.


CSomeCustomControl control;

 

CExtBarButton button;

button.CtrlSet(&control);

 

CExtToolControlBar toolBar;

toolBar.InsertSpecButton(button);


The version of Prof-UIS 2.8.0


Thank you,


Keith

Technical Support Jun 6, 2009 - 1:51 PM

It’s possible to insert buttons with attached windows to the customizable toolbars, but these attached windows will not appear when the user drops such toolbar buttons onto a menu and the several instances of your custom controls attached to toolbar buttons will not be synchronized by Prof-UIS automatically. The customizable toolbars and menus are better without windows attached to toolbar buttons. So, it would be interesting to discuss details of your task.

The customize site creates the toolbar button objects in the CExtCustomizeSite::OnCreateToolbarButton() virtual method. You can override this method if you need to use your own CExtBarButton-class instances. Then the customize site inserts the toolbar buttons into the toolbar control using the CExtToolControlBar::InsertSpecButton() virtual method. You can override this virtual method, invoke parent class method, create your custom control inside toolbar and attach it into inserted toolbar button.

Keith Degrace Jun 5, 2009 - 2:07 PM

These custom control buttons are very specific to the toolbar in question.  It would be ideal if we could prevent these commands from even appearing in the Customize dialog.  This would prevent the the user from being able to drop them into menus, or other toolbars.


It would also be ideal if the toolbar in question would not be customizable by the user (i.e. not possible to drop buttons onto it).  However, this is less of a problem.


I was able to get something working with OnCreateToolbarButton() as you suggested, however there seems to be a small problem.  The toolbar in question can have many different button configurations.  Some configurations contain custom control buttons, while some do not.  When chaging configuration, the toolbar is first clear.  It seems that clearing the toolbar is not properly destroying the attached window.  Here is a snipet of code that is used to clear the toolbar before repopulating it with another set of buttons:


CExtCustomizeCmdTreeNode *activeNode = site.GetToolbarCmdNode(this, false);
if (activeNode != NULL)
    activeNode ->RemoveAllNodes();

The net result is that all the buttons are removed from the toolbar, however the attached windows are still visible.


Is this the proper way to clear a customizable toolbar?

Technical Support Jun 6, 2009 - 1:48 PM

The custom controls can be attached to the toolbar buttons using the CExtToolControlBar::SetButtonCtrl() or CExtBarButton::CtrlSet() methods. Both methods have the bool bCtrlAutoDestroyed flag parameter which should be set to true if the attached control deletes itself in the overridden CWnd::PostNcDestroy() virtual method or class instance is not instantiated using the C++ new operator, and should be set to false otherwise. But there is one issue related to the un-destroyed windows and it should be fixed in the destructor of the CExtBarButton class:

CExtBarButton::~CExtBarButton()
{
CExtAnimationSite * pAcAS = AnimationClient_SiteGet();
            if( pAcAS != NULL )
                        pAcAS->AnimationSite_ClientRemove( this );
            _DestroyMenu();
            m_arrChildren.RemoveAll();
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
HDWP hPassiveModeDWP = NULL;
            OnKeyTipTrackingQuery( false, NULL, hPassiveModeDWP );
#endif // from (!defined __EXT_MFC_NO_CUSTOMIZE)
            CtrlSet( NULL ); // destroy attached window
}


If you are going to switch to the non-customizable toolbar, then you can hide any of your toolbars from the Prof-UIS customization subsystem (CExtCustomizeSite), then you should set its CExtToolControlBar::m_bCustomizationAllowed property to false before initializing customization subsystem.



Technical Support Jun 5, 2009 - 1:44 PM

It’s possible to insert the buttons with attached windows into customizable toolbars, but these attached windows will not appear when the user drop such toolbar buttons into menu and the several instances of your custom controls attached to toolbar buttons will not be synchronized by Prof-UIS automatically. The customizable toolbars and menus are better without windows attached to toolbar buttons. So, it would be interesting to discuss details of your task.

The customize site creates the toolbar button objects in the CExtCustomizeSite::OnCreateToolbarButton() virtual method. You can override this method if you need to use your own CExtBarButton-class instances. Then the customize site inserts the toolbar buttons into the toolbar control using the CExtToolControlBar::InsertSpecButton() virtual method. You can override this virtual method, invoke parent class method, create your custom control inside toolbar and attach it into inserted toolbar button.