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 » Adding combo Box to Toolbar Collapse All
Subject Author Date
Ian McIntosh May 15, 2007 - 4:42 AM

Hi.

I am trying to add a combo box to a toolbar. I have got the combo box to display in the toolbar, but it appears empty and disabled.

I have the following -

in the .h:

CExtToolControlBar m_wndToolBar;
CExtComboBox m_comboType;

in the .cpp:

// BLOCK 1: add a refresh button which works correctly.
int nButtonsCount = m_wndToolBar.GetButtonsCount();
CGuiMdiApp::RegisterCommand(ID_STATE_BUT_REFRESH,
m_wndToolBar, IDI_REFRESH, "refresh list" );
m_wndToolBar.InsertButton(nButtonsCount++, ID_STATE_BUT_REFRESH );

// BLOCK2: create the combo control to be added to the toolbar:
if( !m_comboType.Create(
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS,
CRect( 0, 0, 200, 480 ),
&m_wndToolBar,
ID_COMBO_STATE_TYPE
)
)
{
ASSERT(FALSE);
return -1;
}

// BLOCK3: if I add this code, the combo box is at least displayed, although empty & disabled.
CGuiMdiApp::RegisterCommand(m_comboType.GetDlgCtrlID(),
m_wndToolBar, IDI_CLEAR, "State Type" );
m_wndToolBar.InsertButton(nButtonsCount++, m_comboType.GetDlgCtrlID() );

// BLOCK4: asserts if I dont have the code in block 3.
m_wndToolBar.SetButtonCtrl(
m_wndToolBar.CommandToIndex(ID_COMBO_STATE_TYPE),
&m_comboType
);

// BLOCK5
m_comboType.SetItemHeight( -1, 16 );
m_comboType.SetFont( &g_PaintManager->m_FontNormal );

// BLOCK6: the code in the FAQ has only 1 param for CmdGetPtr(). Anyway, this block doesn’t seem to do anything.
g_CmdManager->CmdGetPtr(
g_CmdManager->ProfileNameFromWnd( m_hWnd ),
m_comboType.GetDlgCtrlID()
)-> m_sMenuText = _T( "State Type" );

// BLOCK7: this data never seems to get displayed.
m_comboType.AddString("One");
m_comboType.AddString("Two");
m_comboType.SetCurSel(0);

Would be grateful for any advice.

Ian McIntosh May 15, 2007 - 9:37 AM

Thanks for swift and helpful answer. All now working.

Technical Support May 15, 2007 - 8:20 AM

All the toolbar buttons are controlled by the MFC’s command updating mechanism in anu of the followind control bars: toolbar, menu bar, panel bar, ribbon page and ribbon bar. So, if a combo box button in your toolbar is assigned the ID_COMBO_STATE_TYPE command identifier, the main frame or dialog window should have the following methods and message map entries for this command:

// insert this into the message map of the main frame/dialog window
ON_UPDATE_COMMAND_UI(ID_COMBO_STATE_TYPE, OnUpdateMyCombo )

// insert this into the class declaration in the .H file
afx_msg void OnUpdateMyCombo( CCmdUI * pCmdUI );

// insert this into the class implementation in the .CPP file
void CMainFrame::OnUpdateMyCheck( CCmdUI * pCmdUI )
{
    pCmdUI->Enable();
}