我作了一个类似outlook的界面,然后想切换视图总是失败。请问如何切换啊?

解决方案 »

  1.   

    切换完后,再加上RecalcLayout();最好将代码贴出来。
      

  2.   

    我用CGfxOutBarCtrl在
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    中创建了左侧的outlookbar,然后想切换视图。
    在用getactiveview()获取活动视图时出错,不能获取当前活动视图的指针。如果不创建outlookbar,就不存在这个问题。
    是不是createclient的原因? 其代码如下:
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    // Create the splitter window with two columns
    if (!m_wndSplitter.CreateStatic(this, 1, 2))
    {
    TRACE0("Failed to create splitter window\n");
    return FALSE;
    }

    // "Flexible pane": The second pane may present its own
    // splitter windows.
    if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CContainerView),
    CSize(0, 0), pContext))
    {
    TRACE0("Failed to create CContainerView\n"); 
    return FALSE;
    } DWORD dwStyle = 
    CGfxOutBarCtrl::fDragItems    |
    CGfxOutBarCtrl::fEditGroups   |
    CGfxOutBarCtrl::fEditItems    |
    CGfxOutBarCtrl::fRemoveGroups |
    CGfxOutBarCtrl::fRemoveItems  |
    CGfxOutBarCtrl::fAddGroups    |
    CGfxOutBarCtrl::fAnimation;

    // Here we create the outbar control; we give as id the parent splitter pane id here
    if (!m_wndOutlookBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0),
    &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), dwStyle))
    {
    TRACE0("Failed to create outlook bar.");
    return FALSE;
    }
        
    // Tell the control to send message to this window (the mainframe) 
    // and not to its real parent (the splitter)
    m_wndOutlookBar.SetOwner(this);

    // Here we create the imagelists for the control
    m_ImageSmall.Create (16, 16, TRUE, 2, 1);
    m_ImageLarge.Create (32, 32, TRUE, 2, 1); for( int nIcon = IDI_ICON_OUTLOOK; nIcon <= IDI_ICON_PUBLIC; ++nIcon ) 
    {
    HICON hIcon = AfxGetApp()->LoadIcon(nIcon);
    ASSERT(hIcon); m_ImageSmall.Add(hIcon);
    m_ImageLarge.Add(hIcon);
    } // and we link them to the control
    m_wndOutlookBar.SetImageList(&m_ImageLarge, CGfxOutBarCtrl::fLargeIcon);
    m_wndOutlookBar.SetImageList(&m_ImageSmall, CGfxOutBarCtrl::fSmallIcon); m_wndOutlookBar.SetAnimationTickCount(20);
    m_wndOutlookBar.SetAnimSelHighlight(200); // Look at function reference for information about linking image list
    // Here we can add the folders to the control; we need at least one folder.
    // The numbers aside the text are an "lParam" value we can assign to each folder
    m_wndOutlookBar.AddFolder(_T("Outlook Shortcuts"),  FOLDER_0);
    m_wndOutlookBar.AddFolder(_T("My Shortcuts"), FOLDER_1); // Here we insert the items; syntax is folder, index, text, image, lParam value for item
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_00, _T("Outlook Today"),  0, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_01, _T("Inbox"),    1, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_02, _T("Calendar"),    2, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_03, _T("Contacts"),    3, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_04, _T("Tasks"),    4, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_05, _T("Journal"),    5, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_06, _T("Notes"),        6, 0);
    m_wndOutlookBar.InsertItem(FOLDER_0, CMD_07, _T("Deleted Items"),  7, 0);

    m_wndOutlookBar.InsertItem(FOLDER_1, CMD_00, _T("Drafts"),    8, 0);
    m_wndOutlookBar.InsertItem(FOLDER_1, CMD_01, _T("Outbox"),    9, 0);
    m_wndOutlookBar.InsertItem(FOLDER_1, CMD_02, _T("Sent Items"),   10, 0);

    m_wndOutlookBar.SetSelFolder(0); // Standard sizing for splitter
    CRect r;
    GetClientRect(&r);
    int w1 = r.Width()/7;
    int w2 = r.Width()/5;
    m_wndSplitter.SetColumnInfo( 0, w1, 0 );
    m_wndSplitter.SetColumnInfo( 1, w2, 0 );
    m_wndSplitter.RecalcLayout(); return TRUE;
    }