请问如何在对话框中调用工具条?

解决方案 »

  1.   

    参考一下,,祝你好运
    CToolBar m_wndToolBar;//in .h
    if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
    TRACE0("Failed to Create Dialog Toolbar\n");
    EndDialog(IDCANCEL);
    }CRect rcClientOld; // 久客户区RECT
    CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT
    GetClientRect(rcClientOld); // 
    CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);CRect rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD);  //得到子窗口
    while(pwndChild) // 处理所有子窗口
    {
    pwndChild->GetWindowRect(rcChild);
    ScreenToClient(rcChild); 
    rcChild.OffsetRect(ptOffset); 
    pwndChild->MoveWindow(rcChild,FALSE); 
    pwndChild = pwndChild->GetNextWindow();
    }
    CRect rcWindow;
    GetWindowRect(rcWindow); // 得到对话框RECT
    rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // 修改对话框尺寸
    rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); 
    MoveWindow(rcWindow,FALSE); // Redraw WindowRepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
      

  2.   

    CToolBar m_wndToolBar;//in .h
    if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
    TRACE0("Failed to Create Dialog Toolbar\n");
    EndDialog(IDCANCEL);
    }
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);这两句话足够了。一般情况下,控件会自动调整位置的。