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

2025-05-27 0 65

个人认为简单问题最好就是直接贴源代码,一看就明白,说来说去反而弄不清楚,那我就少废话了,自己看吧,注释很清楚。

先来张图片

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

1. 新建一个MFC对话框程序MySplitterDlg。 再插入两个Dialog资源 ,这里一定要选择IDD_FORMVIEW类别的对话框,分别新建类CMyFormView0 和CMyFormView1,基类别选CDialog,一定要选择CFormView。

2. CMySplitterDlg中增加WM_CREATE的消息响应,编辑OnCreate()

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20
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

?

1

2

3

4

5

6

7

8

9

10

11
int CMySplitterDlg::OnInitDialog()

{

CDialog::OnInitDialog();

GetWindowRect(&cRect);

ScreenToClient(&cRect);

m_pMyFrame->MoveWindow(&cRect);

m_pMyFrame->ShowWindow(SW_SHOW);

return TRUE;

}

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 VC实现对话框窗口任意分割 https://www.kuaiidc.com/75698.html

相关文章

发表评论
暂无评论