环境:VS Professional 2022
基于对话框分割视图,按网友所述新建一个对话框CDefEditor,两个CFormView类对象CViewDefList、CViewDefPair。
粘贴代码如下:
CDefEditor.h
CFrameWnd* m_pMyFrame=nullptr;
CSplitterWnd m_cSplitter;
CDefEditor.CPP
int CDefEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
GetClientRect(m_recClient);
// 注册主框架窗口类
CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,
::LoadCursor(NULL, IDC_ARROW), (HBRUSH) ::GetStockObject(WHITE_BRUSH),
::LoadIcon(NULL, IDI_APPLICATION));
// 创建框架窗口
m_pMyFrame = new CFrameWnd;
m_pMyFrame->Create(strMyClass, _T(""), WS_CHILD, CRect(0, 0, 1000, 800), this);
m_pMyFrame->ShowWindow(SW_SHOW);
// and finally, create the splitter with the frame as the parent
if (m_cSplitter.CreateStatic(m_pMyFrame, 1, 2)) //在Frame里切分视图窗口为2×2,就是两行两列
{
m_cSplitter.CreateView(0, 0, RUNTIME_CLASS(CViewDefList), CSize(0,0), NULL);//第一行一列
m_cSplitter.CreateView(0, 1, RUNTIME_CLASS(CViewDefPair), CSize(0,0), NULL);//第一行二列
}
return 0;
}
void CDefEditor::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
if (m_pMyFrame)
{
CRect cRect;
GetWindowRect(&cRect);
ScreenToClient(&cRect);
m_pMyFrame->MoveWindow(&cRect);
m_pMyFrame->ShowWindow(SW_SHOW);
}
}
调试时在ONSize函数中报错,一星期了也没弄明白,请指正错在哪里。