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 Tech Support » Toolbar button with drop down arrow and list Collapse All
Subject Author Date
Neville Franks Mar 30, 2005 - 8:32 PM

Hi,


I want a toolbar button with drop down arrow and list. This would be the same as the Back and Forward buttons in Internet Explorer where you click on the button and the action is executed and you click on the arrow and the list is displayed. Selecting a list item executes the command with the selected item.


Also like these IE buttons I want to dynamically set the button’s tooltip text.


So how can I do both of these things?


Thanks,
Neville


 

Technical Support Apr 1, 2005 - 8:18 AM

To set tooltip text or any other parameter for a command dynamically, you need to retrieve the CExtCmdItem object from the command manager and set appropriate values:

CExtCmdItem * pCmdItem =
g_CmdManager->CmdGetPtr( strProfileName, ID_SOME_CMD );
ASSERT( pCmdItem != NULL );
pCmdItem->m_sTipStatus = _T("Tip Status");
pCmdItem->m_sTipTool = _T("Tip Tool");
m_sTipStatus stores the text that is displayed in the status bar.
m_sTipTool stores the text that is displayed in the balloon tooltip over the menu items and in the ordinary tooltip over the toolbar buttons.

Neville Franks Mar 31, 2005 - 7:31 PM

I have worked out how pTBB->SetSeparatedDropDown() along with adding a menu can be used but that isn’t ideal for me.


I would prefer the drop down arrow to work the same as a Toolbar combo box does and call CMainFrame::OnPopupListBoxInitContent() etc.  I need to dynamically build the drop down content.


I’ve seen CExtPopupUndoRedoMenuWnd which is closer to what I want assume this is not appropriate for my needs. I can’t find any documentation for this either.


I also discovered what appears to be a bug. When a button has menu attached and the button is disabled you can still click on the drop down arrow and the menu is displayed.

Technical Support Apr 1, 2005 - 8:36 AM

There is a very simple method to create a toolbar button with a separated drop-down area which is tracking the dynamically created menu.

1) Create a toolbar button with a drop-down menu and assign a menu (e.g.,IDR_DYNAMIC_POPUP_MENU) to it. This menu contains a temporary menu item with a certain ID (e.g., ID_TEMP)

INT nBtnIdx = m_wndToolBar.CommandToIndex( ID_SOME_CMD );
ASSERT( nBtnIdx >= 0 );
CMenu _line_menu;
VERIFY( _line_menu.LoadMenu( IDR_DYNAMIC_POPUP_MENU ) );
VERIFY( m_wndToolBar.SetButtonMenu( 
    nBtnIdx, _line_menu.Detach() ) );
CExtBarButton * pTBB = 
   m_wndToolBar.GetButton(nBtnIdx);
ASSERT_VALID( pTBB );
pTBB->SetSeparatedDropDown();
2) The CExtPopupMenuWnd::g_nMsgPrepareMenu message is sent each time a menu is about to appear on the screen. So, just search for the temporary menu item with the specified ID in message handler, and, if it is found, just remove it and add any required item(s):
LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
{
   CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
      reinterpret_cast<
         CExtPopupMenuWnd::MsgPrepareMenuData_t *
       >( wParam );
   ASSERT( pData != NULL );
   CExtPopupMenuWnd * pPopup = pData->m_pPopup;
   ASSERT( pPopup != NULL );
   
   INT nItemPos = pPopup->ItemFindPosForCmdID( 
      ID_TEMP 
    );

   if( nItemPos >= 0 )
   {
      pPopup->ItemRemove( nItemPos );
      pPopup->ItemInsert(
         nCmdID,
         nItemPos
      );
   }
}

Neville Franks Apr 4, 2005 - 1:50 AM

Thanks, that works and will do what I want.


Is there a way to get the users menu selection via. a CMainFrame function instead of using ON_COMMAND(). The reason I want to do this is to be able to access the selected menu items MENUITEMDATA::LParamGet().

Technical Support Apr 4, 2005 - 8:48 AM

The menu LParam value is usually used to get some additional information about a menu item when a menu is constructed. When a command is handled, there is no way to find from where this command has been sent. It may be a menu item, a toolbar button or a piece of code that fired this command. Please tell us more about what you actually need so we can help you find an alternative way.

Neville Franks Apr 5, 2005 - 2:34 AM

I thought there may have been a way to access the menus LParam when a menu item was selected but it doesn’t matter. I am processing the menu selection using the normal ON_COMMAND code and working backwards from there. So everything is ok.

Technical Support Apr 5, 2005 - 8:15 AM

You can use the CExtPopupMenuWnd::g_nMsgItemCoveringNotification notification message, which is sent to the parent window when the user highlights a menu item with the mouse pointer or keyboard or hovers the mouse pointer over a toolbar button. In case of menu items, this message is similar to the standard windows message WM_MENUSELECT. This should allow you to use the last menu/toolbar item that has been selected and analyze it in the ON_COMMAND handler.

We added a FAQ regarding this issue Is there a way to handle the highlighting of menu items and toolbar buttons?, so it may be useful for you.