BOOL CMySheet::OnInitDialog()
{
//load menu
CMenu Menu;
if(Menu.LoadMenu( IDR_MENU )==0)
{
MessageBox("LOAD MENU ERROR!",NULL,MB_OK);
}
SetMenu(&Menu);

//load toolbar
CToolBar ToolBar;
ToolBar.Create(this);
if(ToolBar.LoadToolBar(IDR_TOOLBAR)==0)
{
MessageBox("LOAD ToolBar ERROR!",NULL,MB_OK);
}
ToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |CBRS_ALIGN_BOTTOM |CBRS_ALIGN_ANY   );
ToolBar.ShowWindow(SW_SHOW);
...........
}

解决方案 »

  1.   

    上面的代码只能添加菜单,不能添加工具栏。并且LoadToolBar函数执行是正确的。
      

  2.   

    添加工具栏成员变量m_wndToolbar
    BOOL CMySheet::OnInitDialog()
    {
    .......................
    //CREATE TOOLBAR
    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);
    return TRUE;
    }
      

  3.   

    我的
    CMySheet继承自CPropertyPage