我把窗口静态拆分成两个,可是怎样才能限制分割线的移动,或者直接让它固定我本想继承CSplitterWnd类自己重写,可是用程序向导却找不到CSplitterWnd基类。各位有什么办法,请教教!谢谢

解决方案 »

  1.   

    http://www.codeguru.com/splitter/restrict_size.shtmlhttp://www.codeguru.com/mfc/comments/28896.shtml
    Just override WM_NCHITTEST message, from your derived CSplitterWnd class, then I add a member variable called m_bLock, and the following functions: 
    // public void CSplitterWndEx::Lock( BOOL bLock ) 

    m_bLock = bLock; 
    } // override the WM_NCHITTEST message UINT CSplitterWndEx::OnNcHitTest( CPoint point ) 

    if( m_bLock ) 
    return HTNOWHERE; // if locked 
    return CSplitterWnd::OnNcHitTest( point ); 
    } Also remember to init m_bLock with a default from the contructor, after creating your splitter and views, call m_wndSplitterWnd.Lock( TRUE ); // to lock splitter Have fun... Regards Shaun 
    Submitted By: Shaun (2001/11/11) 
      

  2.   

    very easy!
    --------------------------------------
    Add new class derived from CSplitterWnd 
    and then mask the message WM_MOUSEMOVE,WM_SETCURSOR,WM_LBUTTON
    directly uses the message of CWnd as the following :
    then replace your CSplitterWnd with CFixedSplitter 
    enjoy it!
    -------------
    #if !defined(AFX_FIXEDSPLITTER_H__9DB2BF9B_1C2E_483F_985E_FC38AB087B05__INCLUDED_)
    #define AFX_FIXEDSPLITTER_H__9DB2BF9B_1C2E_483F_985E_FC38AB087B05__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // FixedSplitter.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CFixedSplitter windowclass CFixedSplitter : public CSplitterWnd
    {
    // Construction
    public:
    CFixedSplitter();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CFixedSplitter)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CFixedSplitter(); // Generated message map functions
    protected:
    //{{AFX_MSG(CFixedSplitter)
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_FIXEDSPLITTER_H__9DB2BF9B_1C2E_483F_985E_FC38AB087B05__INCLUDED_)------------------
    // FixedSplitter.cpp : implementation file
    //#include "stdafx.h"
    #include "Fun.h"
    #include "FixedSplitter.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CFixedSplitterCFixedSplitter::CFixedSplitter()
    {
    }CFixedSplitter::~CFixedSplitter()
    {
    }
    BEGIN_MESSAGE_MAP(CFixedSplitter, CSplitterWnd)
    //{{AFX_MSG_MAP(CFixedSplitter)
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONDOWN()
    ON_WM_SETCURSOR()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    /////////////////////////////////////////////////////////////////////////////
    // CFixedSplitter message handlersvoid CFixedSplitter::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    CWnd::OnMouseMove(nFlags, point);
    }void CFixedSplitter::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    CWnd::OnLButtonDown(nFlags, point);
    }BOOL CFixedSplitter::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
    {
    // TODO: Add your message handler code here and/or call default

    return CWnd::OnSetCursor(pWnd, nHitTest, message);
    }---------------------
    添加类时,选择基类为 Generic CWnd
    然后再相应的h文件和cpp文件中,用CSplitterWnd代替CWnd