Sunday, January 27, 2008

to have controls in a toolbar in MFC

int nIdx = CommandToIndex(nToolBarBtnID);
ASSERT( nIdx >= 0 );
SetButtonInfo(nIdx, nComboID, TBBS_SEPARATOR, 50);
const int nDropHeight = 50;
CRect rect;
GetItemRect(nIdx, &rect);
rect.top = 1;
rect.bottom = rect.top + nDropHeight;
if (!m_comboBox.Create(CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP | WS_CHILD, rect, this, nComboID))
{
TRACE0("Failed to create combobox in ToolBar\n");
return false;
}
// update the combo with a font.
m_comboFont.CreatePointFont( 80,_T("MS Sans Serif"));
m_comboBox.SetFont( &m_comboFont );
m_comboBox.EnableWindow(FALSE);
// show the combobox.
m_comboBox.ShowWindow( SW_SHOWNORMAL );
return true;

In the toolbar that you have created make a button which will be place holder for the
combo(control in this example).....

just pass the placeholders Id and a new Id for the combo box

No comments: