如何切换视口而不破坏它们?


我创建了一个带有静态分隔区的sdi应用程序,左边显示工作区,右过显示左边选取的东西.我想达到的是如果在分隔区之间进行切换,而不覆盖或破坏原来的CView对象.

以下代码是你所想要的:

class CExSplitterWnd : public CSplitterWnd
{
// Construction
public:
    CExSplitterWnd();
// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CExSplitterWnd)
    //}}AFX_VIRTUAL
// Implementation
    virtual ~CExSplitterWnd();
    BOOL AttachView(CWnd* pView, int row, int col);
    BOOL DetachView(int row, int col);
    // Generated message map functions
    //{{AFX_MSG(CExSplitterWnd)
        // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CExSplitterWnd::CExSplitterWnd()
{
}

CExSplitterWnd::~CExSplitterWnd()
{
}

BOOL CExSplitterWnd::AttachView(CWnd* pView, int row, int col)
{
    //Make sure the splitter window was created
    if (!IsWindow(m_hWnd))
    {
        ASSERT(0);
        TRACE(_T("Create the splitter window before attaching windows to panes"));
        return (FALSE);
    }

    //Make sure the row and col indices are within bounds
    if (row >= GetRowCount() || col >= GetColumnCount())
    {
        ASSERT(0);
        return FALSE;
    }

    //Is the window to be attached a valid one
    if (pView == NULL || (!IsWindow(pView->m_hWnd)))
    {
        ASSERT(0);
        return FALSE;
    }

    pView->SetDlgCtrlID(IdFromRowCol(row, col));
    pView->SetParent(this);
    pView->ShowWindow(SW_SHOW);
    pView->UpdateWindow();
    return (TRUE);
}

BOOL CExSplitterWnd::DetachView(int row, int col)
{
    //Make sure the splitter window was created
    if (!IsWindow(m_hWnd))
    {
        ASSERT(0);
        TRACE(_T("Create the splitter window before attaching windows to panes"));
        return (FALSE);
    }

    //Make sure the row and col indices are
    //within bounds
    if (row >= GetRowCount() || col >= GetColumnCount())
    {
        ASSERT(0);
        return FALSE;
    }

    CWnd* pWnd = GetPane(row, col);
    if (pWnd == NULL || (!IsWindow(pWnd->m_hWnd)))
    {
        ASSERT(0);
        return FALSE;
    }

    pWnd->ShowWindow(SW_HIDE);
    pWnd->UpdateWindow();

    //Set the parent window handle to NULL so that this child window is not
    //destroyed when the parent (splitter) is destroyed
    pWnd->SetParent(NULL);
    return (TRUE);
}

[返回“一学网www.onestudy.net”首页]