要在Dialog中加入自己的浮动工具条,该怎么做?

解决方案 »

  1.   

    创建工具条的代码
    m_pImageList = new CImageList;
    SetupImages(m_pImageList);TBBUTTON tb;m_ToolBar = new CToolBarCtrl;
    m_ToolBar->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TBSTYLE_FLAT,
    CRect(0,0,0,0), this, 0);m_ToolBar->SetImageList(m_pImageList);
    tb.iBitmap = 0;
    tb.iString = NULL;
    tb.fsState = TBSTATE_ENABLED;
    tb.fsStyle = TBSTYLE_BUTTON;
    tb.idCommand = ID_HELP_ABOUT;m_ToolBar->AddButtons(1, &tb);
    tb.iBitmap = 1;
    tb.idCommand = ID_BOLD;
    m_ToolBar->AddButtons(1, &tb);
    tb.iBitmap = 2;
    tb.idCommand = ID_DRAWING;
    m_ToolBar->AddButtons(1, &tb);TBBUTTON tb1;
    tb1.fsStyle = TBSTYLE_SEP;
    m_ToolBar->AddButtons(1, &tb1);tb.iBitmap = 3;
    tb.idCommand = ID_STRIKEOUT;
    tb.iString = NULL;
    m_ToolBar->AddButtons(1, &tb);创建状态条的代码:
    m_StatusBar = new CStatusBarCtrl;
    m_StatusBar->Create(WS_CHILD|WS_VISIBLE|SBT_OWNERDRAW,
    CRect(0,0,0,0), this, 0);int strPartDim[4]= {180, 260, 340, -1};
    m_StatusBar->SetParts(4, strPartDim);m_StatusBar->SetText(_T("Dialog / StatusBar / Toolbar"),0,0);
    m_StatusBar->SetText(_T("Example"), 1, 0);CString string;
    string.LoadString(IDS_MYCOMPUTER);
    m_StatusBar->SetText(string, 3 ,SBT_NOBORDERS );
    m_StatusBar->SetIcon(3, 
    SetIcon(AfxGetApp()->LoadIcon(IDI_COMP),
    FALSE));
      

  2.   


      BOOL CYourDlg::OnInitDialog()
      {
           CDialog::OnInitDialog();     
     
           // Create the toolbar. To understand the meaning of the styles used, you 
           // can take a look at the MSDN for the Create function of the CToolBar class.
           ToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_BORDER_BOTTOM);
     
          // I have assumed that you have named your toolbar's resource as IDR_TOOLBAR1.
          // If you have given it a different name, change the line below to accomodate 
          // that by changing the parameter for the LoadToolBar function.
          ToolBar.LoadToolBar(IDR_TOOLBAR1);
      
          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);
      
         return TRUE;  // return TRUE  unless you set the focus to a control
      }
        
      

  3.   

    补充:关键代码就两行,剩下都是窗口移动问题
    ToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_BORDER_BOTTOM);
    ToolBar.LoadToolBar(IDR_TOOLBAR1);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);