“没有新的文档出现”是什么意思?不明白。能不能说的具体一点? MFC打开文档的过程是这样的:首先是CWinApp::OnFileOpen(),这个函数只是简单调用CDocManager::OnFileOpen()。CDocManager::OnFileOpen()负责显示文件对话框,然后调用CWinApp::OpenDocumentFile()打开选择的文件。 你使用CWinApp::OpenDocumentFile()了吗?仔细检查你的代码,这个问题应该比较简单。
解决方案 »
- 如何在DLL中创建SDI/MDI
- Activex控件奇怪问题
- VC中的文件长度问题?
- 求教关于对话框键盘接口!
- 小弟急问,关于dll加载的问题
- 应用程序调用DLL异常,其原因可能是堆被损坏,这也说明 中或它所加载的任何DLL 中有bug
- getpixel的返回值用什么类型的变量接收?
- 请问大家,VC中的三个Server是干什么的(安装时可以选的)
- BCG、VS2008下组框(group-box)很难看
- 请问大家一个问题:要是microsoft倒了,咱们还有饭吃么?请来发表你的看法!
- 谁有huffman解压缩的源码,Mail给我一份(急用)[email protected]
- 自己造的字如何发布到其它计算机上?
另外,出错的原因还可能是因为你注册的多个模板中没有与打开文件匹配的类型。这时CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)将返回NULL,即无法打开文档。这个函数如下(copy自MFC,^_^):CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
// find the highest confidence
POSITION pos = m_templateList.GetHeadPosition();
CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt;
CDocTemplate* pBestTemplate = NULL;
CDocument* pOpenDocument = NULL; TCHAR szPath[_MAX_PATH];
ASSERT(lstrlen(lpszFileName) < _countof(szPath));
TCHAR szTemp[_MAX_PATH];
if (lpszFileName[0] == '\"')
++lpszFileName;
lstrcpyn(szTemp, lpszFileName, _MAX_PATH);
LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
if (lpszLast != NULL)
*lpszLast = 0;
AfxFullPath(szPath, szTemp);
TCHAR szLinkName[_MAX_PATH];
if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
lstrcpy(szPath, szLinkName); while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
ASSERT_KINDOF(CDocTemplate, pTemplate); CDocTemplate::Confidence match;
ASSERT(pOpenDocument == NULL);
match = pTemplate->MatchDocType(szPath, pOpenDocument);
if (match > bestMatch)
{
bestMatch = match;
pBestTemplate = pTemplate;
}
if (match == CDocTemplate::yesAlreadyOpen)
break; // stop here
} if (pOpenDocument != NULL)
{
POSITION pos = pOpenDocument->GetFirstViewPosition();
if (pos != NULL)
{
CView* pView = pOpenDocument->GetNextView(pos); // get first one
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame != NULL)
pFrame->ActivateFrame();
else
TRACE0("Error: Can not find a frame for document to activate.\n");
CFrameWnd* pAppFrame;
if (pFrame != (pAppFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd))
{
ASSERT_KINDOF(CFrameWnd, pAppFrame);
pAppFrame->ActivateFrame();
}
}
else
{
TRACE0("Error: Can not find a view for document to activate.\n");
}
return pOpenDocument;
} if (pBestTemplate == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
return NULL;
} return pBestTemplate->OpenDocumentFile(szPath);
}
而不是那个刚刚被打开的窗口。下面是我的OnFileOpen()
{
CWinApp* pWinApp;
pWinApp = (CWinApp*) AfxGetApp( );
static char szFilter[]="BMP FILES(*.BMP)|*.BMP||";
FileDialog FileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY, szFilter);
if(FileDlg.DoModal()==IDOK){
pWinApp->OpenDocumentFile(FileDlg.GetPathName());
m_pDib->Load( FileDlg.GetPathName());
}
}
其中,m_pDib是定义在CMyDoc中的一个指向图象类(CDib)的指针,Load()用来读取文件进内存