在一个SDI程序里面,我在InitInstance()这个函数里增加了这样的代码,但程序启动时出现了一个打开文档的错误,当按下弹出对话框的确定按钮时,程序就退出了,不知原因出在哪,希望大侠能给予答疑释惑。 CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); if(cmdInfo.m_strFileName.GetLength()==0) //打开程序时同时打开上次关闭的文档
{
if(m_pRecentFileList-> m_nSize> 0
&& m_pRecentFileList-> m_arrNames[0].IsEmpty()==FALSE)
{
cmdInfo.m_strFileName = m_pRecentFileList-> m_arrNames[0];
cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
}
else
{
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
} // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
顺便贴一张我写的小秘书公文包的一个截图吧:
ParseCommandLine(cmdInfo); if(cmdInfo.m_strFileName.GetLength()==0) //打开程序时同时打开上次关闭的文档
{
if(m_pRecentFileList-> m_nSize> 0
&& m_pRecentFileList-> m_arrNames[0].IsEmpty()==FALSE)
{
cmdInfo.m_strFileName = m_pRecentFileList-> m_arrNames[0];
cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
}
else
{
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
} // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
顺便贴一张我写的小秘书公文包的一个截图吧:
AfxGetApp()->AddToRecentFileList(XxxxFileName);
使用了这个函数问题得到解决,谢谢!当天解决当天结贴去。
{
// TODO: Add your specialized code here and/or call the base class
for (int j=0;j<4;j++)
{
CString fn=RFileList->m_arrNames[j];
CFileStatus Status;
if (CFile::GetStatus(fn,Status)==FALSE) // not exist
RFileList->Remove(j);
}
return CWinApp::OnIdle(lCount);
}
搭车请教,这个函数会把信息保存到哪里?注册表,还是ini?
http://www.codeproject.com/KB/docview/most_recent_used.aspx
参考一下这个,希望对你有帮助~
m_pRecentFileList->WriteList();进行写注册表,最后CSSBriefcaseApp* pApp = (CSSBriefcaseApp*)AfxGetApp();
pApp-> m_pDocManager->OpenDocumentFile((LPCTSTR)m_pRecentFileList-> m_arrNames[0]);才得以解决问题。谢谢大家的意见! 我还不知7楼的方法是否可行,以后再试下吧。