我用mfc做了几个程序,现在我想把这几个程序的功能集成在一起。就是想做一个sdi程序,把视图分为2部分,左边是一排按钮。点击其中一个右边出现相应的页面。(把几个功能放一个程序上)
像这样做的话,需要把视图继承自什么类呢。我原来的程序基本都是对话框程序和一个cformview视图

解决方案 »

  1.   

    网上找个SwitchView函数,这个可以根据不同的需要随时切换显示某个视图
      

  2.   

    用CSPlietWnd分割界面,然后视图还是继承CFormView,主要工作是点击按钮的时候进行右边视图的切换。
      

  3.   

    在网上查这个函数SwitchViewInSplitter
      

  4.   

    我现在就想要界面是这样的:
    1.视图是CFormView,分成固定的2部分。
    2.左边是一些按钮,点击任意一个按钮,右边显示相应的页面(对话框样式)
      

  5.   

    基于CFormView进行视图的分割,然后创建若干对话框,通过点击左边的按钮
    控制右边的对话框ShowWindow(SW_HIDE);或者ShowWindow(SW_SHOWNORMAL);
      

  6.   

    继承CSPlietWnd 然后重载WM_LBUTTONCLICKED
      

  7.   

    我在网上找到这样一段代码:
    在创建了一个单文档的工程后,先添加类CSplitterWndEx,其基类为CSplitterWnd,在MainFrame引用了头文件后就添加一个CSplitterWndEX的成员变量:  CSplitterWndEx m_wndSplitter; 然后在MainFrame的客户区创建事件的处理函数中添加分割的代码: 
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
    {
         CRect rect;     
     GetClientRect(rect); 
         if(!m_wndSplitter.CreateStatic(this, 1, 2)) 
            return FALSE; 
         if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftPaneView),CSize(rect.Width()/4,100),pContext)) 
        return FALSE;  
         if (!m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CMainInterface),CSize(100,100),pContext)) 
    return FALSE;      return TRUE; }
    可我编译就出现错误如下:
    error C2653: 'CLeftPaneView' : is not a class or namespace name
    F:\My\MainFrm.cpp(78) : error C2065: 'classCLeftPaneView' : undeclared identifier
    F:\My\MainFrm.cpp(80) : error C2653: 'CMainInterface' : is not a class or namespace name
    F:\My\MainFrm.cpp(80) : error C2065: 'classCMainInterface' : undeclared identifier
    Error executing cl.exe.My.exe - 4 error(s), 0 warning(s)
    这怎么解决啊
      

  8.   

    1.你有没有添加那两个类啊,或者包含那两个类的头文件了没有啊
    2.固定分隔条的办法是在重载的CSplitterWnd类里面,把OnMouseMove()事件的代码里面只添加
    return;(即直接返回)就行了
      

  9.   

    CLeftPaneView 和 CMainInterface 这两个视图类也要定义啊!你也不一定用分割窗口吧?
    用属性页或者树形控件呢?
      

  10.   

    在网上查这个函数 SwitchViewInSplitter 
      

  11.   

    我觉的这CLeftPaneView是不是代表着左边的页面啊,我添加了这个类,并把它与一个CFormView的对话框资源连接起来。
    CMainInterface是不是代表总的放置左右页面的页面啊。我也添加了这个类,使它与一个CFormView的对话框资源连接起来。
    编译没错,运行有问题,说找不到文件。SwitchViewInSplitter 这个函数我找到了
    是用于交换视图的对吗。
      

  12.   

    应该是先用CSPlietWnd分割界面,再用SwitchViewInSplitter 这个函数来交换视图吧
      

  13.   

    我手动添加OnMouseMove()事件,怎么总是出错啊?照着向导的三步做的啊
      

  14.   

    我看了这篇文章,加了这些代码;
    固定分隔条(不让别人拖动):锁定切分条的最简单的方法莫过于不让CSplitterWnd类来处理WM_LBUTTONDOWN,WM_MOUSEMOVE,WM_SETCURSOR消息,而是将这些消息交给CWnd窗口进行处理,从而屏蔽掉这些消息。现在我们打开CMySplitter类的头文件,我们手动的添加一些东西(为什么要手动呢?因为,我们选择的是Generic Class),好了,我们来看一下都加入了哪些代码:class CSplitterWndEx : public CSplitterWnd 
    {
    public:
    CSplitterWndEx();
    virtual ~CSplitterWndEx();//以固定分隔条加入的代码DECLARE_DYNCREATE(CSplitterWndEx)
      
    protected:
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    DECLARE_MESSAGE_MAP()//以上是固定分隔条加入的代码
    };我们仔细的看一下在DECLARE_DYNCREATE(CMySplitter)和DECLARE_MESSAGE_MAP()之间是消息处理的声明,告诉计算机,我们重载了这三个消息处理函数。现在我们在打开CSplitterWndEx类的.cpp文件,在构造函数CSplitterWndEx::CSplitterWndEx()上面加入如下代码:IMPLEMENT_DYNCREATE(CSplitterWndEx, CSplitterWnd)BEGIN_MESSAGE_MAP(CSplitterWndEx, CSplitterWnd)
    ON_WM_LBUTTONDOWN()
    ON_WM_SETCURSOR()
    ON_WM_MOUSEMOVE()
    END_MESSAGE_MAP()
    在程序结尾添加下面的代码:void CSplitterWndEx::OnLButtonDown(UINT nFlags, CPoint point)
    {     
        // 直接返回,不处理
    return;
    }BOOL CSplitterWndEx::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {   
        // 当光标进入分割窗口时,不允许改变样子,不处理
    return FALSE;
    }void CSplitterWndEx::OnMouseMove(UINT nFlags, CPoint point)
    {            //将CSplitter类的处理改为由CWnd处理
          //CSplitterWnd::OnMouseMove(nFlags, point); 
        CWnd::OnMouseMove(nFlags, point);
    }好了,这样我们就实现了分隔条的固定。这一步是比较有难度的,因为我们要自己写一些消息处理代码。结果编译有错误,如下;
    rror C2601: 'CreateObject' : local function definitions are illegal
    F:\8\SplitterWndEx.cpp(21) : error C2601: '_GetBaseClass' : local function definitions are illegal
    F:\8\SplitterWndEx.cpp(21) : error C2655: 'classCSplitterWndEx' : definition or redeclaration illegal in current scope
            f:\8\splitterwndex.h(17) : see declaration of 'classCSplitterWndEx'
    F:\8\SplitterWndEx.cpp(21) : error C2601: 'GetRuntimeClass' : local function definitions are illegal
    F:\8\SplitterWndEx.cpp(23) : error C2601: '_GetBaseMessageMap' : local function definitions are illegal
    F:\8\SplitterWndEx.cpp(23) : error C2601: 'GetMessageMap' : local function definitions are illegal
    F:\8\SplitterWndEx.cpp(23) : error C2655: 'messageMap' : definition or redeclaration illegal in current scope
            f:\8\splitterwndex.h(25) : see declaration of 'messageMap'
    F:\8\SplitterWndEx.cpp(23) : error C2655: '_messageEntries' : definition or redeclaration illegal in current scope
            f:\8\splitterwndex.h(25) : see declaration of '_messageEntries'
    Generating Code...
    Compiling...
    8.cpp
    Generating Code...
    Skipping... (no relevant changes detected)
    MainFrm.cpp
    Error executing cl.exe.8.exe - 8 error(s), 0 warning(s)
    不知道什么原因啊
      

  15.   

    DECLARE_DYNCREATE(CSplitterWndEx) 
    IMPLEMENT_DYNCREATE(CSplitterWndEx, CSplitterWnd) 
    这两行代码去掉
      

  16.   

    我删除了这2行代码,可是还是有错误编译。 
    rror C2601: '_GetBaseMessageMap' : local function definitions are illegal 
    E:\9\SplitterWndEx.cpp(22) : error C2601: 'GetMessageMap' : local function definitions are illegal 
    E:\9\SplitterWndEx.cpp(22) : error C2655: 'messageMap' : definition or redeclaration illegal in current scope 
            e:\9\splitterwndex.h(25) : see declaration of 'messageMap' 
    E:\9\SplitterWndEx.cpp(22) : error C2655: '_messageEntries' : definition or redeclaration illegal in current scope 
            e:\9\splitterwndex.h(25) : see declaration of '_messageEntries' 
    Error executing cl.exe. 9.exe - 4 error(s), 0 warning(s) 
      

  17.   

    cformview类  然后CSplitterWndEx分割