请教  那高手会在对话框上放置工具栏。
我用vc生成一个对话框的应用, 请问如何在这个对话框中生成一个工具栏????谢谢!!!

解决方案 »

  1.   

    BOOL CFlowShowDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog(); //初始化工具条
    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
    }
        // Create the toolbar. To understand the meaning of the styles used, you 
      
    CRect rcClientStart;
    CRect rcClientNow;
    GetClientRect(rcClientStart); // To reposition and resize the control bar
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0, reposQuery, rcClientNow);
    CPoint ptOffset(rcClientNow.left - rcClientStart.left,rcClientNow.top-rcClientStart.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);
    rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
    rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
    MoveWindow(rcWindow, FALSE);         // And position the control bars
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
    //
    /* for(int i = 0; i < m_wndToolBar.GetCount(); i++) 

     UINT id = m_wndToolBar.GetItemID(i);
     CString s; 
     if(!s.LoadString(id)) 
     continue; 
     int j=s.Find(_T('\n'));
     if(j < 0) continue; 
     s=s.Right(s.GetLength()-j-1); 
     m_wndToolBar.SetButtonText(i,s); 
    } // Add drop-down arrow to File|New button 
    // m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
    i=m_wndToolBar.CommandToIndex(ID_NODE_START);
    UINT id,style;
    int image;
    m_wndToolBar.GetButtonInfo(i,id,style,image);
    m_wndToolBar.SetButtonInfo(i,ID_NODE_START,TBSTYLE_BUTTON | TBSTYLE_DROPDOWN,image); 
    // Adjust sizes to include text CRect rect; 
    CRect rect;
    m_wndToolBar.GetItemRect(0,&rect); 
    m_wndToolBar.SetSizes(rect.Size(),CSize(32,31)); 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
      

  2.   

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

  3.   

    用一个最简单的方法:
    先在对话框中放置一个STATIC空间,然后在这个静态控件的位置创建工具栏就可以了
      

  4.   

    BOOL CTest6Dlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }
    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here 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); // 
    // 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.
    //重新计算RECT大小
    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.
    //所有的子窗口将被移动,以免被TOOLBAR覆盖
    // 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);  //得到子窗口
    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 Window RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  5.   

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

  6.   

    和一般的窗体有什么区别呢?把ParentWnd设为对话框不就行了