正宗的版本~~~
[1]新建对话框程序(此处我将其命名为Dlg2View)
[2]新建三个单文档视图所需的类,View类选择Scroll类型的
[3]在InitInstance()中添加代码
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDlg2ViewDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CDlg2ViewView));
AddDocTemplate(pDocTemplate);
当然要添加三个类的头文件
然后将些列代码注释并替换// CDlg2ViewDlg dlg;
// m_pMainWnd = &dlg;
// int nResponse = dlg.DoModal();
// if (nResponse == IDOK)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with OK
// }
// else if (nResponse == IDCANCEL)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with Cancel
// }
CDlg2ViewDlg dlg;
dlg.DoModal();
[4]为对话框中的按钮添加响应函数
其实就是添加以下代码
theApp.m_pDocManager->OnFileNew(); //弹出单文档视图
不过要先定义theApp咯~
在App类中已经定义,Dlg类中extern即可
[5]为当文档视图添加菜单,不添加会提示"建立空文档失败"