代码如下,加到CMainFrame::OnCreate里面,为什么成功?#define COMBO_BOX_WIDTH 80 //the width of the combo box
#define IDC_MY_COMBO 13001
int index = 0;
CRect rect;
while(m_wndToolBar.GetItemID(index)!= ID_MY_COMBO_BOX) 
index++;
m_wndToolBar.SetButtonInfo(index, ID_MY_COMBO_BOX, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
m_wndToolBar.GetItemRect(index, &rect); CComboBox m_wndMyComboBox;
rect.top+=2;
rect.bottom += 200;
if (!m_wndMyComboBox.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL | 
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, &m_wndToolBar, IDC_MY_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndMyComboBox.ShowWindow(SW_SHOW);
m_wndMyComboBox.AddString("Fisrt Select");
m_wndMyComboBox.AddString("Second Select");
m_wndMyComboBox.AddString("Third Select");
m_wndMyComboBox.SetCurSel(0);

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=469
      

  2.   

    他的例子派生了CToolBar类,
    上面的方法为什么不行?
      

  3.   

    bool CMainFrame::InitToolbar()
    {
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return false;      // fail to create
    } const int nCmbHeight = 200;
    const int nCmbWidth  = 120;
    m_wndToolBar.SetButtonInfo(nIndex, IDC_CMB_HIERARCHYPROP, TBBS_SEPARATOR, 120); CRect rect;
    m_wndToolBar.GetItemRect(nIndex,rect);
    rect.top = 1;
    rect.bottom = rect.top + 200; if(!m_cmbDevHP.Create(CBS_OWNERDRAWVARIABLE|CBS_DROPDOWNLIST|CBS_HASSTRINGS|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
    rect,&m_wndToolBar,IDC_CMB_HIERARCHYPROP))
    {
    return false;
    } for(int i = 1; i <= 10; ++i )
    {
    m_cmbDevHP.AddString("xxx");
    }
    }
      

  4.   

    上面的那个m_cmbDevHP是带有自绘风格的combo
      

  5.   

    上面的到下面这里有错误
    void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
    { ASSERT(FALSE); }去掉CBS_OWNERDRAWVARIABLE没有错误了,可还是看不到toolbar上的combobox
      

  6.   

    那个片段是我的程序里面的, 差别就是用的一个OWNERDRAW风格的COMBOBOX,
    我的运行是完全OK的,继承TOOLBAR与否是没关系的,把相关的代码提取出来就可以了的你再检查一下你的代码,
    good luck!