现在的位置: 首页 > 综合 > 正文

关于用CSplitterWnd分割View的一点总结

2017年09月07日 ⁄ 综合 ⁄ 共 1385字 ⁄ 字号 评论关闭

1.在要分割的View中添加OnCreate消息响应函数 ;

2.分割函数:

int CUserManagerSplitterView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    
if (CView::OnCreate(lpCreateStruct) == -1)
        
return -1;
    
    
if(!m_wndUserSplitter.CreateStatic(this12))
    
{
        
return FALSE;
    }


    BOOL bRet 
= m_wndUserSplitter.CreateView(00, RUNTIME_CLASS(CUserLeftPanView), CSize(200100), NULL);
    
if(!bRet)
    
{
        TRACE0(
"Failed to create left user pan!");
        
return FALSE;
    }


    bRet 
= m_wndUserSplitter.CreateView(01, RUNTIME_CLASS(CUserRightPanView), CSize(100100), NULL);
    
if(!bRet)
    
{
        TRACE0(
"Failed to create right user pan!");
        
return FALSE;
    }


    m_wndUserSplitter.RecalcLayout();

    
    
return 0;
}

 

3.添加OnSize()响应,显示SplitterWnd:

void CUserManagerSplitterView::OnSize(UINT nType, int cx, int cy) 
{
    CView::OnSize(nType, cx, cy);

    
if(this->m_hWnd != NULL)
    
{
        CRect rect;
        GetClientRect(
&rect);

        
if(m_wndUserSplitter.GetSafeHwnd() != NULL)
        
{    
            m_wndUserSplitter.MoveWindow(
&rect);            
        }


    }

    
}

3.如果要Left Pan 与 Right Pan 可相互通信,参考以下代码:

//在CUserLeftPanView 中定义: CUserRightPanView *m_pUserRightPanView;
//然后在OnCreate后面添加:

CUserLeftPanView
* pUserLeftPanView = (CUserLeftPanView*)m_wndSplitter.GetPane(00);
pUserLeftPanView
->m_pRightPanView= (CUserRightPanView*)m_wndSplitter.GetPane(01); 

4.分割Frame方法一样;

 

抱歉!评论已关闭.