C++ Can';我不明白SDI是如何工作的

C++ Can';我不明白SDI是如何工作的,c++,visual-c++,mfc,C++,Visual C++,Mfc,我正在尝试使用空白项目创建文本编辑器。我很难把我的头缠在SDI的头上。这到底在干什么?还有,我如何使用这些类 auto-pDocTemplate=new-CSingleDocTemplate( IDR_大型机, 运行时_类(BaseDocument), 运行时_类(基架), 运行时_类(BaseView)); 如果(!pDocTemplate) 返回FALSE; addDoctTemplate(pDocTemplate); 我试着像这样使用文档: auto xtra = (BaseDocum

我正在尝试使用空白项目创建文本编辑器。我很难把我的头缠在SDI的头上。这到底在干什么?还有,我如何使用这些类

auto-pDocTemplate=new-CSingleDocTemplate(
IDR_大型机,
运行时_类(BaseDocument),
运行时_类(基架),
运行时_类(BaseView));
如果(!pDocTemplate)
返回FALSE;
addDoctTemplate(pDocTemplate);
我试着像这样使用文档:

auto xtra = (BaseDocument*)pDocTemplate->OpenDocumentFile(newDlg.currPath);
它返回一个“文件无法打开”错误

编辑:当我尝试跳过我创建的对话框并运行“模板”代码时,当它到达

if(!ProcessShellCommand(cmdInfo))
返回FALSE

以下是整个应用程序:

BEGIN_MESSAGE_MAP(BaseApp, CWinApp)
ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
END_MESSAGE_MAP()

BaseApp::BaseApp() {
SetAppID(_T("AbduTextEditor"));
}


BaseApp::~BaseApp()
{
}
BaseApp theApp;

BOOL BaseApp::InitInstance() {
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);

CWinApp::InitInstance();

SetRegistryKey(_T("AbduTextEditor"));
LoadStdProfileSettings(5);

m_pRecentFileList->ReadList();

auto pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(BaseDocument),
    RUNTIME_CLASS(BaseFrame),
    RUNTIME_CLASS(BaseView));


if (!pDocTemplate)
    return FALSE;
AddDocTemplate(pDocTemplate);
/*
BeginningDlg newDlg;
BOOL newdoc;

for (auto i = 0; i <= 4; i++) {
    newDlg.rf.Add(m_pRecentFileList->operator[](i));
}

switch (newDlg.DoModal()) {
case 1:
    newdoc = FALSE;
    break;
case 3:
    newdoc = TRUE;
    break;
default:
    return FALSE;
}
auto xtra = (BaseDocument*)pDocTemplate- 
>OpenDocumentFile(newDlg.currPath);*/

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);


AfxInitRichEdit2();

EnableShellOpen();
RegisterShellFileTypes(TRUE);

if (!ProcessShellCommand(cmdInfo))
    return FALSE;



m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}


int BaseApp::ExitInstance()
{
m_pRecentFileList->WriteList();

return CWinApp::ExitInstance();
}

您需要覆盖帧的“创建”
消息中的

您是否阅读了
AddDocTemplate
的MSDN文档?文件中有哪些内容不清楚?关于“文件无法打开”:您是否检查了
newDlg.currPath
的值?我意识到这就是您初始化应用程序的方式。但是文件就在那里,我该如何打开一个txt文件呢?我是否正确使用了指针?文档已存在。请在调试器中运行该程序。MFC完全源代码,您可以调试到它。我的水晶球说
newDlg
nullptr
。我投了反对票,因为你没有显示相关的源代码,而且似乎没有尝试调试。如果你愿意,我可以发布整个应用程序
void BeginningDlg::OnBnClickedOpenbutton(){
CString string = _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||");

CFileDialog filedlg(TRUE,nullptr,nullptr, OFN_FILEMUSTEXIST| 
OFN_ENABLEINCLUDENOTIFY,string,this);

filedlg.m_ofn.lpstrInitialDir = path;
INT_PTR pInt = filedlg.DoModal();

if (pInt == IDOK) {
    currPath.Append(filedlg.GetPathName());
    EndDialog(1);
}
}