VC++ MFC 对话框 窗口分割

找了几个教程都比较早了

1).插入三个IDD_FORMVIEW

VC++ MFC 对话框 窗口分割

2)添加类:FormView1, FormView2,FormView3 基类:CFormView

3).在Dlg.h中添加

3.1

#include "FormView1"
#include "FormView2"

#include "FormView3”

3.2在Dlg.h中添加

  1. public:  
  2.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);  
  3.   
  4.   
  5. public:  
  6.     CFrameWnd *m_pMyWnd;  
  7.     CSplitterWnd m_SplitterWnd;  
  8.     CSplitterWnd m_SplitterWnd2;  

3.3在DLg.cpp中定义Oncreate

  1. int CSplitDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)  
  2. {  
  3.     if (CDialog::OnCreate(lpCreateStruct) == -1)  
  4.         return -1;  
  5.   
  6.     CString strMyClass = AfxRegisterWndClass(CS_VREDRAW |CS_HREDRAW,  
  7.         ::LoadCursor(NULL, IDC_ARROW),  
  8.         (HBRUSH) ::GetStockObject(WHITE_BRUSH),  
  9.         ::LoadIcon(NULL, IDI_APPLICATION));  
  10.   
  11.     // Create the frame window with "this" as the parent  
  12.     m_pMyWnd = new CFrameWnd;  
  13.     m_pMyWnd->Create(strMyClass,_T(""), WS_CHILD,  
  14.         CRect(0,0,200,200), this);  
  15.     m_pMyWnd->ShowWindow(SW_SHOW);     
  16.   
  17.   
  18.     if (m_SplitterWnd.CreateStatic(m_pMyWnd,1, 2) == NULL) //1行2列  
  19.     {  
  20.         return -1;  
  21.     }     
  22.   
  23.     if(m_SplitterWnd2.CreateStatic(&m_SplitterWnd,2,1,WS_CHILD|WS_VISIBLE,m_SplitterWnd.IdFromRowCol(0,1)) == NULL)  
  24.     {  
  25.         return -1;  
  26.     }  
  27.   
  28.     m_SplitterWnd.CreateView(0,0, RUNTIME_CLASS(CMyFormViewOne),  
  29.         CSize(100,100), NULL);  
  30.   
  31.     m_SplitterWnd2.CreateView(0,0, RUNTIME_CLASS(CMyFormViewTwo),  
  32.         CSize(80,80), NULL);  
  33.   
  34.     m_SplitterWnd2.CreateView(1,0, RUNTIME_CLASS(CMyFormViewThree),  
  35.         CSize(80,80), NULL);  
  36.  return 0;
  37. }

3.4在Dlg.cpp中OnInitDialog()添加

  1. CRect rect;  
  2. GetWindowRect(&rect);  
  3. ScreenToClient(&rect);  
  4.   
  5. m_pMyWnd->MoveWindow(&rect);  
  6. m_pMyWnd->ShowWindow(SW_SHOW);  
最后结果是C崩了。。。mmp