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 » CExtToolControlBar - dynamic buttons Collapse All
Subject Author Date
Eugen Rata Jul 4, 2005 - 4:50 PM

Hi

another small question.
Here http://www.prof-uis.com/FAQView.aspx?CID=96#_ctl31_divDescr I found how to add dynamically buttons to the toolbar. this works very good!!

the identifiers for buttons I register by using g_CmdManager as described in your article,
// Set it to zero to allow the command manager
// to find the dynamic identifier automatically
pCmdItem = g_CmdManager->CmdAllocPtr( lpszProfileName );

hovewer all the button added to the toolbar are disabled.
I tried to use
pCmdItem->StateEnable();
and even
g_CmdManager->ProfileSetup(pApp->m_pszProfileName,GetSafeHwnd());
g_CmdManager->g_bDisableCmdIfNoHandler = FALSE;
but no result, dynamicaly created buttons are still disabled.

How to enable them and which is the right way to handle notifications from them in MDI applications?

Thx.

Technical Support Jul 5, 2005 - 12:38 PM

Each menu/toolbar item (which is a user-interface object) needs to know whether it is enabled or disabled to display itself properly. If the framework does not find an ON_UPDATE_COMMAND_UI entry during command routing, it automatically enables the user-interface object if there is an ON_COMMAND entry somewhere for the same command ID. Otherwise, it disables the user-interface object. So to ensure your button is enabled, provide an update or command handler for the command ID.

Eugen Rata Jul 5, 2005 - 1:48 PM

thanks for your answer.


well this is clear. But how to provide an update or command handler for command ID which I don’t know? It is generated automatically by your command manager.


I cannot reserve some IDs since the user can add buttons to the toolbar as much as he wants.


Any idea how to solve this problem?


And another question: when I right click on toolbar it is displayed a popup menu with the list of toolbars. this is ok, but is not ok cause the items in that menu are disabled? why would they? I add toolbar as described here on site.


Thx

Technical Support Jul 6, 2005 - 7:54 AM

We guess you know the range of dynamic commands. In this case you can enable them dynamically in the OnCmdMsg() method:

BOOL C_YOUR_Class::OnCmdMsg(
    UINT nID,
    INT nCode,
    void * pExtra,
    AFX_CMDHANDLERINFO * pHandlerInfo
    )
{
    if(     nCode == CN_UPDATE_COMMAND_UI
        &&  ID_YOUR_FIRSRT <= nID
        &&  nID <= ID_YOUR_LAST
        )
        ((CCmdUI*)pExtra)->Enable();
    return
        C_PARENT_Class::OnCmdMsg(
            nID, nCode, pExtra, pHandlerInfo );
}

Eugen Rata Jul 6, 2005 - 11:07 AM

thx. this makes more sense :)

Technical Support Jul 6, 2005 - 8:03 AM

We will explain below how the command descriptions appear in the command profile of the command manager:

1) They can be registered in the command manager when the CExtToolControlBar::LoadToolBar() or CExtCmdManager::UpdateFromToolBar() methods are called.

2) They can also be registered there when the CExtMenuControlBar::LoadMenuBar(), CExtPopupMenuWnd::TrackPopupMenu() or CExtCmdManager::UpdateFromMenu() methods are called.

3) They can be allocated by the user code when the code invokes the CExtCmdManager::CmdAllocPtr() method. This method allows you to find unused command identifiers dynamically.

We guess you are using cases 1 and 2. So, initially you have some toolbars and menus with a set of command identifiers and, in fact, you know all the command identifiers. This means there are no dynamic command identifiers allocated by the command manager. If you use pre-defined command ranges for all the pluggable parts of your software like most of the programs do, then you can update and handle these commands in the OnCmdMsg() method as we described in our previous reply.

As for your second question: The MFC framework automatically handles and updates 32 standard commands corresponding to control bars like the AFX_IDW_TOOLBAR standard command identifier that is exactly equal to the ID_VIEW_TOOLBAR command identifier used as a dialog control identifier of the single toolbar window generated by the application wizard. You should add the appropriate message map lines for all your other toolbars, menu bar and resizable control bars:

ON_COMMAND_EX( ID_VIEW_MENUBAR, OnBarCheck )
ON_UPDATE_COMMAND_UI( ID_VIEW_MENUBAR, OnUpdateControlBarMenu )

Technical Support Jul 6, 2005 - 8:21 AM

We will explain below how the command descriptions appear in the command profile of the command manager:

1) They can be registered in the command manager when the CExtToolControlBar::LoadToolBar() or CExtCmdManager::UpdateFromToolBar() methods are called.

2) They can also be registered there when the CExtMenuControlBar::LoadMenuBar(), CExtPopupMenuWnd::TrackPopupMenu() or CExtCmdManager::UpdateFromMenu() methods are called.

3) They can be allocated by the user code when the code invokes the CExtCmdManager::CmdAllocPtr() method. This method allows you to find unused command identifiers dynamically.

We guess you are using cases 1 and 2. So, initially you have some toolbars and menus with a set of command identifiers and, in fact, you know all the command identifiers. This means there are no dynamic command identifiers allocated by the command manager. If you use pre-defined command ranges for all the pluggable parts of your software like most of the programs do, then you can update and handle these commands in the OnCmdMsg() method as we described in our previous reply.

As for your second question: The MFC framework automatically handles and updates 32 standard commands corresponding to control bars like the AFX_IDW_TOOLBAR standard command identifier that is exactly equal to the ID_VIEW_TOOLBAR command identifier used as a dialog control identifier of the single toolbar window generated by the application wizard. You should add the appropriate message map lines for all your other toolbars, menu bar and resizable control bars:

ON_COMMAND_EX( ID_VIEW_MENUBAR, OnBarCheck )
ON_UPDATE_COMMAND_UI( ID_VIEW_MENUBAR, OnUpdateControlBarMenu )

Eugen Rata Jul 6, 2005 - 11:08 AM

thx, I’ll try