int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
        if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
                return -1;
        
        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 -1;      // fail to create
        }        CRect rect;
        m_wndToolBar.SetButtonInfo(4,IDC_COMBOX,TBBS_SEPARATOR,160);
        m_wndToolBar.GetItemRect(4,&rect);
        rect.bottom+=100;
        if (!m_wndToolBar.m_ComBox.Create(CBS_DROPDOWN|CBS_AUTOHSCROLL|WS_VISIBLE|WS_TABSTOP,
                rect,&m_wndToolBar,IDC_COMBOX))
        {
                return -1;
        }
        
        m_wndToolBar.m_ComBox.AddString("隶书");
        m_wndToolBar.m_ComBox.AddString("宋体");        if (!m_wndStatusBar.Create(this) ||
                !m_wndStatusBar.SetIndicators(indicators,
                  sizeof(indicators)/sizeof(UINT)))
        {
                TRACE0("Failed to create status bar\n");
                return -1;      // fail to create
        }        // TODO: Delete these three lines if you don't want the toolbar to
        //  be dockable
        m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
        EnableDocking(CBRS_ALIGN_ANY);
        DockControlBar(&m_wndToolBar);
        return 0;
}这是我的代码,m_wndToolBar是我自己的类,编译链接的时候都没有问题的,但是执行的时候就崩溃了,各位大牛,帮我看看是哪里出问题了?奇怪的是如果把m_ComBox放在MainFrame里就不会有问题,但是我还是想放在自己的类里··

解决方案 »

  1.   

    调试运行一下 通过callstack看看错在哪里
      

  2.   

    主窗口包含ToolBar,你的ComboBox控件又是在ToolBar上的, 查看一下你的层次关系
      

  3.   

    _wndToolBar是我自己的类,编译链接的时候都没有问题的,但是执行的时候就崩溃了,各位大牛,帮我看看是哪里出问题了?奇怪的是如果把m_ComBox放在MainFrame里就不会有问题
    ---------------------------------------------------
    你把m_ComBox放到CToolBar的派生类中的代码是怎么写的,你写在了哪里呢?