在对话框应用程序中,在资源编辑器中建立了一个工具栏,不知道怎么样才能把这个工具栏显示在界面上和对话框关联起来!请大家指教!多谢!

解决方案 »

  1.   

    http://ycjy.jsipt.edu.cn/jsjx/VC/NewUpdate/Dialog/columnist_paper.pl-aid=alexandrite&pid=toolbar_in_dlg.htm
      

  2.   

    建立和LOAD的部分和CMainFrame中一样。然后把它用MoveWindow放在对话框上合适的位置就行了。
      

  3.   

    从CToolBar派生一个类做为你的工具栏对象.在对话框的OnInitDialog中调用派生的Create和LoadToolBar函数就行了.
      

  4.   

    http://www.copathway.com/vchelp/zsrc/dlgtoolbar.zip
    本例程中:
    1. 在资源中加入IDC_TOOLBAR1工具栏资源
    2. 在.h文件中加入CToolBar m_wndToolBar;变量
    3. 在.cpp文件中OnInitDialog中加入
    if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
      TRACE0("Failed to Create Dialog Toolbar\n");
      EndDialog(IDCANCEL);
    }
    CRect rcClientOld; // Old Client Rect
    CRect rcClientNew; // New Client Rect with Tollbar Added
    GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
    // Called to reposition and resize control bars in the client area of a window
    // The reposQuery FLAG does not really traw the Toolbar. 
    // It only does the calculations.
    // And puts the new ClientRect values in rcClientNew 
    // so we can do the rest of the Math.
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,
      reposQuery,rcClientNew);// All of the Child Windows (Controls) now need to be moved 
    // so the Tollbar does not cover them up.
    // Offest to move all child controls after adding Tollbar
    CPoint ptOffset(rcClientNew.left-rcClientOld.left,
      rcClientNew.top-rcClientOld.top);CRect rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD);  //Handle to the Dialog Controls
    while(pwndChild) // Cycle through all child controls
    {
      pwndChild->GetWindowRect(rcChild); //  Get the child control RECT
      ScreenToClient(rcChild); 
      rcChild.OffsetRect(ptOffset); 
        // Changes the Child Rect by the values of the claculated offset
      pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
      pwndChild = pwndChild->GetNextWindow();
    }CRect rcWindow;
    GetWindowRect(rcWindow); // Get the RECT of the Dialog
    rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); 
      // Increase width to new Client Width
    rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); 
      // Increase height to new Client Height
    MoveWindow(rcWindow,FALSE); // Redraw Window// Now we REALLY Redraw the Toolbar
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
    以上就完成了对话框中加入工具栏
    4. 使工具栏的按钮失效和有效。
    AfxMessageBox("Button A Pressed - Button D Disabled");
    CToolBar* pBar = &m_wndToolBar;
    UINT iButtonID;
    UINT iButtonStyle; 
    int  iButtonImage;
    pBar->GetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
    iButtonStyle = TBBS_DISABLED; //无效
    如果iButtonStyle = 0;则是使有效
    pBar->SetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
      

  5.   

    http://www.copathway.com/vchelp/zsrc/dlgtoolbar.zip
    本例程中:
    1. 在资源中加入IDC_TOOLBAR1工具栏资源
    2. 在.h文件中加入CToolBar m_wndToolBar;变量
    3. 在.cpp文件中OnInitDialog中加入
    if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
      TRACE0("Failed to Create Dialog Toolbar\n");
      EndDialog(IDCANCEL);
    }
    CRect rcClientOld; // Old Client Rect
    CRect rcClientNew; // New Client Rect with Tollbar Added
    GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
    // Called to reposition and resize control bars in the client area of a window
    // The reposQuery FLAG does not really traw the Toolbar. 
    // It only does the calculations.
    // And puts the new ClientRect values in rcClientNew 
    // so we can do the rest of the Math.
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,
      reposQuery,rcClientNew);// All of the Child Windows (Controls) now need to be moved 
    // so the Tollbar does not cover them up.
    // Offest to move all child controls after adding Tollbar
    CPoint ptOffset(rcClientNew.left-rcClientOld.left,
      rcClientNew.top-rcClientOld.top);CRect rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD);  //Handle to the Dialog Controls
    while(pwndChild) // Cycle through all child controls
    {
      pwndChild->GetWindowRect(rcChild); //  Get the child control RECT
      ScreenToClient(rcChild); 
      rcChild.OffsetRect(ptOffset); 
        // Changes the Child Rect by the values of the claculated offset
      pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
      pwndChild = pwndChild->GetNextWindow();
    }CRect rcWindow;
    GetWindowRect(rcWindow); // Get the RECT of the Dialog
    rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); 
      // Increase width to new Client Width
    rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); 
      // Increase height to new Client Height
    MoveWindow(rcWindow,FALSE); // Redraw Window// Now we REALLY Redraw the Toolbar
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
    以上就完成了对话框中加入工具栏
    4. 使工具栏的按钮失效和有效。
    AfxMessageBox("Button A Pressed - Button D Disabled");
    CToolBar* pBar = &m_wndToolBar;
    UINT iButtonID;
    UINT iButtonStyle; 
    int  iButtonImage;
    pBar->GetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
    iButtonStyle = TBBS_DISABLED; //无效
    如果iButtonStyle = 0;则是使有效
    pBar->SetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);