我想开发一个像MS—Outlook2002那个的GUI,左边儿是拉帘式的窗口格,右边是Edit等视图。 也就是说,左边窗口格和右边儿窗格都要有装两个以上的视图。
在MainFrm.cpp中加入以下代码:BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
// TODO: Add your specialized code here and/or call the base class
if (!m_wndSplitter.CreateStatic(this, 1, 2)) //创建一个切分窗口 this为窗口本身,1为行,2为列
{
TRACE0("Failed to create splitter window\n");
return FALSE;
}CRect rect;
GetClientRect(&rect); //取窗口的大小 // 创建左边的Pane,是个构架(frame),含拉帘视图(View)
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftframe), CSize(rect.Width()/3, 0), pContext))
{
TRACE0("Failed to create left pane view\n");
return FALSE;
} //创建右边的Pane,也是个构架(frame),含多个视图(View)
// The is can be set to active or non-active
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightFrame), CSize(0, 0), pContext))
{
TRACE0("Failed to create right pane frame\n");
return FALSE;
}
    //返回窗格Pane的指针,
CLeftframe* pLeftframe     = (CLeftframe*)   m_wndSplitter.GetPane(0,0);
pLeftframe ->m_pRightPaneFrame = (CRightFrame*) m_wndSplitter.GetPane(0,1);

// Set the left pane as the active view
SetActiveView((CView*) m_wndSplitter.GetPane(0, 1)); return TRUE;
}也就是说,用m_wndSplitter.CreateView创建的不是View,而Frame,一个是LeftFrame,另一个是CRightFrame。 而生成的左边Frame和右边儿的Frame都是从CFrameWnd派生而来。 它们都要分别再创建自己的几个视图(View)。
我写的代码,左边儿的Frame没什么问题。右边儿的出了点问题。我在RightFrame.cpp中的OnCreateClient加入以下代码。
BOOL CRightFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
// TODO: Add your specialized code here and/or call the base class
m_pCFORMVIEW2 = new CFORMVIEW2;
m_pCFORMVIEW2->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, CMainFrame, VIEW_SPLITTER, pContext);
SetActiveView(m_pCFORMVIEW2);
m_pCFORMVIEW2->ShowWindow(SW_SHOW);
m_pCFORMVIEW2->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();但总出错。
E:\My Documents\A计划\工程\demo_adbook\RightFrame.cpp(42) : error C2275: 'CMainFrame' : illegal use of this type as an expression
        e:\my documents\a计划\工程\demo_adbook\mainfrm.h(12) : see declaration of 'CMainFrame'
Error executing cl.exe.demo_adbook.exe - 1 error(s), 0 warning(s)
不知道哪位有兴趣和我讨论一下这个问题。
如果愿意的话,也可以和我用QQ来讨论,我会把我写的代码发给你看。
QQ:16693611
MSN:[email protected]

解决方案 »

  1.   

    CRect rectDefault,rectMails,rectAccounts; rectDefault = CFrameWnd::rectDefault;
    rectAccounts = CRect(rectDefault.left,rectDefault.top,rectDefault.Width()/2,rectDefault.Height());
    rectMails = CRect(rectDefault.left + rectDefault.Width()/2,rectDefault.top,rectDefault.Width()/2,rectDefault.Height()); m_pViewSplitter = new CSplitterView;
    m_pViewSplitter->Create(NULL,NULL,0L,rectDefault,this,VIEW_ACCOUNTSANDMAILS,pContext);
    SetActiveView(m_pViewSplitter);
    m_pViewSplitter->ShowWindow(SW_SHOW);
    m_pViewSplitter->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
    m_nCurrentView = VIEW_ACCOUNTSANDMAILS;
      

  2.   

    我以前就用用this,但也不行。
      

  3.   

    http://www.vccode.com/file_show.php?id=1629
    http://www.vccode.com/file/20020920131811_mvSplitter.rar程序说明:    原作者 Caroline Englebienne。代码大小:27k。
        环境:VC 6下面是翻译的作者的说明:这篇文章介绍了怎样在一个切分窗口中切换多个view,而又不是通过删除重建view的方法。删除重建view的方法的方法效率很底,并且总是会打断程序设计的思路。然而我现在能找到的唯一一个切分窗口中切换多个view的例子就是使用的这个方法,所以我写了这个代码。注意:这个类只能用在静态切分中,不能用在动态切分中。怎样使用我的代码我从CSplitterWnd继承了一个类(AW_CMultiViewSplitter)。你可以在你的工程中加入AW_CMultiViewSplitter.h和AW_CMultiViewSplitter.cpp文件,使用AW_CMultiViewSplitter类代替标准的切分窗口并调用下面两个函数:int AddView(int nRow, int nCol, CRuntimeClass * pViewClass, CCreateContext* pContext) 
    这个函数在你平常要调用CreateView()函数的地方调用,但是你希望要又多个view。如果你只需要一个view,那么你只要调用CreateView()。AddView()返回一个int值,它是新创建view的ID。这个ID在调用ShowView()时使用。 void ShowView(int viewID)
    功能是隐藏当前的view,显示需要的view。两个重要功能1.怎样在一个切分窗口中创建多个view
    2.怎样在多个view中做切分怎样在一个切分窗口中创建多个view下面的代码说明了怎样在一个切分窗口中添加新的view:
    HideCurrentView(nRow, nCol)
    {
    CWnd * pView = GetCurrentView(pane.row, pane.col);
    pView->SetDlgCtrlID(0);
    pView->ShowWindow(SW_HIDE);
    }CreateView(nRow, nCol, pViewClass, CSize(10,10), pContext);SetCurrentView(nRow, nCol, newViewID)
    {
    CWnd * pView = GetView( viewID);
    pView->SetDlgCtrlID(IdFromRowCol(pane.row, pane.col));
    pView->ShowWindow(SW_SHOW);
    }怎样切换
    viewGetPaneFromViewID(viewID);
    HideCurrentView(pane.row, pane.col);
    SetCurrentView(pane.row, pane.col, viewID);
      

  4.   

    一个效果很好的outlookbar控件CXTOutBarCtrl 
    发布者: xuchyu ——>查看xuchyu在VCCode发布的所有文章  文章类型:原创  
    发布日期:2003.02.27    
    升级次数:0  
    今日浏览:7  
    总浏览:1409  --------------------------------------------------------------------------------
     
    评价等级:       
     代码下载  
    2位用户为此文章评分,平均分为4.5 该控件来源于Xtreme Toolkit,我对其进行了修改,使其一依赖于类库独立存在,由于我没有运用XT的其他类,可能你会觉得它没有在类库的华丽,但相对于其小巧的体格而言,已经很难得了。 源文件包括两个头文件,两个执行文件:XTMemDC.h,XTMemDC.cpp,XTOutBarCtrl.h,XTOutBarCtrl.cpp. 其中XTMemDC是一个CDC继承类,用于辅助功能。 该控件的使用方法:
    1,用mfc sdi wizard生成一个子SDI程序。2,在MainFrm.h头部加入#include "XTOutBarCtrl.h" 3,在MainFrm.h是加入成员变量 CSplitterWnd m_wndSplitter; 
    CXTOutBarCtrl m_wndOutlookBar; CImageList m_ImageLarge; 
    CImageList m_ImageSmall; 
    bool m_bDestroy; 
    4,CMainFrame增加消息映射函数BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 

    // create splitter window 
    if (!m_wndSplitter.CreateStatic(this, 1, 2)) 
    return FALSE; // Here we create the outbar control using the splitter as its parent 
    // and setting its id to the first pane. 
    if (!m_wndOutlookBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(0,0,0,0), 
    &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), OBS_XT_DEFAULT)) 

    TRACE0("Failed to create outlook bar."); 
    return FALSE; 
    } if (!m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, 
    CSize(100, 100), pContext)) 

    m_wndSplitter.DestroyWindow(); 
    return FALSE; 
    } // Set the background and text color of the outlook bar. 
    m_wndOutlookBar.SetBackColor(RGB(0x3a,0x6e,0xa5)); 
    m_wndOutlookBar.SetTextColor(RGB(0xff,0xff,0xff)); // Set the default sizes for the splitter panes. 
    CRect r; 
    GetClientRect(&r); 
    m_wndSplitter.SetColumnInfo( 0, r.Width()/4, 0 ); 
    m_wndSplitter.RecalcLayout(); // Add items to the outlook bar. 
    InitializeOutlookBar(); return TRUE; 

    5,CMainFrame增加成员函数 void CMainFrame::InitializeOutlookBar() 

    // Create the image lists used by the outlook bar. 
    m_ImageSmall.Create (16, 16, ILC_COLOR16|ILC_MASK, 2, 1); 
    m_ImageLarge.Create (32, 32, ILC_COLOR16|ILC_MASK, 2, 1); // initiailize the image lists. 
    for (int i = 0; i < 11; ++i) 

    HICON hIcon = AfxGetApp()->LoadIcon(nIcons[i]); 
    ASSERT(hIcon); m_ImageSmall.Add(hIcon); 
    m_ImageLarge.Add(hIcon); 
    } int iFolder; // index of the added folder // set the image lists for the outlook bar. 
    m_wndOutlookBar.SetImageList(&m_ImageLarge, OBS_XT_LARGEICON); 
    m_wndOutlookBar.SetImageList(&m_ImageSmall, OBS_XT_SMALLICON); // Add the first folder to the outlook bar. 
    iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 1"), 0); // Add items to the folder, syntax is folder, index, text, image, and item data. 
    m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 3, _T("Item 3"), 2, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 4, _T("Item 4"), 3, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 5, _T("Item 5"), 4, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 6, _T("Item 6"), 5, NULL); // Add the second folder to the outlook bar. 
    iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 2"), 1); // Add items to the folder, syntax is folder, index, text, image, and item data. 
    m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL); 
    m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL); // Add the tree control to the outlook bar. 
    //xu iFolder = m_wndOutlookBar.AddFolderBar(_T("Tree Control"), &m_wndTreeCtrl ); // Set the default font used by the outlook bar. 
    //xu m_wndOutlookBar.SetFontX(&xtAfxData.font); // We want to receive notification messages. 
    m_wndOutlookBar.SetOwner(this); // Select the first folder in the bar. 
    m_wndOutlookBar.SetSelFolder(iFolder); // Sizing for splitter 
    CRect r; 
    GetClientRect(&r); 
    m_wndSplitter.SetColumnInfo( 0, r.Width()/7, 0 ); 
    m_wndSplitter.SetColumnInfo( 1, r.Width()/5, 0 ); 
    // m_wndSplitter1.SetSplitterStyle(XT_SPLIT_NOFULLDRAG); } 
    6,CMainFrame增加消息映射 LRESULT CMainFrame::OnOutbarNotify(WPARAM wParam, LPARAM lParam) 

    int nBarAction = (int)wParam; // Cast the lParam to a XT_OUTBAR_INFO* struct pointer. 
    XT_OUTBAR_INFO* pOBInfo = (XT_OUTBAR_INFO*)lParam; 
    ASSERT(pOBInfo); switch (nBarAction) 

    case OBN_XT_ITEMCLICK: 
    TRACE2( "Item selected: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_FOLDERCHANGE: 
    TRACE2( "Folder selected: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_ONLABELENDEDIT: 
    TRACE2( "Item edited: %d, New name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_ONGROUPENDEDIT: 
    TRACE2( "Folder edited: %d, New name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_DRAGITEM: 
    TRACE3( "Dragging From: %d, To: %d, Name: %s.\n", pOBInfo->nDragFrom, pOBInfo->nDragTo, pOBInfo->lpszText); 
    break; case OBN_XT_ITEMHOVER: 
    TRACE2( "Hovering Item: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_DELETEITEM: if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove this folder shortcut?"), 
    MB_ICONWARNING|MB_YESNO) == IDNO) 

    // The user selected No, return FALSE to abort the action. 
    return FALSE; 

    TRACE2( "Item deleted: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; case OBN_XT_DELETEFOLDER: 
    if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove the specified folder?"), 
    MB_ICONWARNING|MB_YESNO) == IDNO) 

    // The user selected No, return FALSE to abort the action. 
    return FALSE; 

    TRACE2( "Folder deleted: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); 
    break; 
    } return TRUE; 

    还有其他一些内容请参见源程序,愿这个控件能对您的编程有所帮助,谢谢。  http://www.vccode.com/file_show.php?id=1629
      

  5.   

    就该用this,如果不行,是其它的原因。我用这个实现了一个类Foxmail的界面。
    应该是分出一个面板以后再从这个面板的OnCreateClient中分出两个或者多个。
      

  6.   

    Switching views in splitter panes (SDI) 发布者: soarlove ——>查看soarlove在VCCode发布的所有文章
    http://www.vccode.com/file_show.php?id=824
      

  7.   

    http://www.vckbase.com/document/viewdoc.asp?id=511
    这地方又一个模仿OutLook程序的文章,并且有源程序下载,可以过去看看!