protected:
CToolBar m_wndToolBar;if(!m_wndToolBar.CreateEx( this,TBSTYLE_FLAT ,  WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS|CBRS_TOP,CRect(4,4,0,0))  || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
    TRACE0("Failed to Create Dialog Toolbar\n");
    EndDialog(IDCANCEL);
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);

解决方案 »

  1.   

    在OnInitDialog()里加入如下代码:
    if(!m_wndToolBar.Create(this,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS|CBRS_SIZE_DYNAMIC)||!m_wndToolBar.LoadToolBarEx(m_bForCheck?IDR_TOPBAR:IDR_NOPOSTIL))
    {
    TRACE("Create toolbar failed!\n");
    return -1;
    }m_wndToolBar.ModifyStyle(0,TBSTYLE_FLAT);//如果需要FLAT样式的加上RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
      

  2.   

    int CDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CDialog::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here
    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_TESTTOOLBAR)) 
    {
    TRACE0("Failed to create toolbar\n"); // fail to create 
    }

    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
    return 0;
    }