VC实现对话框窗口任意分割

效果图:


1. 新建一个MFC对话框程序MySplitterDlg。 再插入两个Dialog资源 ,对话框style:Child,Border:None

           分别新建类CMyFormView1 和CMyFormView2,注意:基类别选CDialog,一定要选择CFormView。

2. CMySplitterDlg中添加变量:

     CFrameWnd* m_pMyFrame;
           CSplitterWnd m_cSplitter;

增加WM_CREATE的消息响应,编辑OnCreate()

int CMySplitterDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
    // Because the CFRameWnd needs a window class, we will create a new one. I just copied the sample from MSDN Help.
    // When using it in your project, you may keep CS_VREDRAW and CS_HREDRAW and then throw the other three parameters.
    //需要注册窗口类
    CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,  
                   ::LoadCursor(NULL, IDC_ARROW),    (HBRUSH) ::GetStockObject(WHITE_BRUSH),   
                  ::LoadIcon(NULL, IDI_APPLICATION));

    // Create the frame window with "this" as the parent
    m_pMyFrame = new CFrameWnd;
    m_pMyFrame->Create(strMyClass,"", WS_CHILD,   CRect(0,0,300,300), this);
    m_pMyFrame->ShowWindow(SW_SHOW);

    // and finally, create the splitter with the frame as the parent
    m_cSplitter.CreateStatic(m_pMyFrame,1, 2); //在Frame里切分视图窗口为1×2,就是一行两列
    m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CMyFormView0),   CSize(100,100), NULL);//第一行一列
    m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CMyFormView1), CSize(100,100), NULL);//第一行二列

     return 0;
}

3. 在CMySplitterDlg::OnInitDialog()中显示Frame
int CMySplitterDlg::OnInitDialog()
{
CDialog::OnInitDialog();

GetWindowRect(&cRect);
ScreenToClient(&cRect);
m_pMyFrame->MoveWindow(&cRect);
m_pMyFrame->ShowWindow(SW_SHOW);


return TRUE;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值