OnFileOpen与OnOpenDocument
来源:互联网 发布:模拟开车的软件 编辑:程序博客网 时间:2024/05/18 03:14
OnFileOpen是菜单项的响应函数,由它具体调用那个对话框并完成文件的搜索和最终路径的确认。
OnOpenDocument应该是在文件已经选好准备打开的时候触发的,这个时候应该可以处理文件内的具体数据了,所以你具体载入图像应该来重载这个函数,还有View的Update相关函数也要重载。
CWinApp::OnFileOpen调用CDocManager::OnFileOpen。
CDocManager::OnFileOpen首先显示文件打开对话框(AFX_IDS_OPENFILE),然后调用CWinApp:: OpenDocumentFile(FileName)。
CWinApp::OpenDocumentFile(FileName)调用CDocManager::OpenDocumentFile。
CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)遍历文档模板,对每个模板用MatchDocType(szPath,pOpenDocument)匹配文档类型。匹配时主要根据文件扩展名判断。若文件已经在某个文档中打开,则激活文档的第一个视图,否则用匹配的文档模板pBestTemplate->OpenDocumentFile(szPath)。
CDocTemplate::OpenDocumentFile调用CDocument::OnOpenDocument打开文件。
CDocument::OnOpenDocument打开文件,用DeleteContents删除现有文档内容,创建文件对应的CArchive
对象loadArchive,Serialize(loadArchive)读文件内容,SetModifiedFlage(FALSE)。
CWinApp::OnFileOpen函数大概执行以下步骤:
1、提示用户选择文件;
2、选择一个匹配的文件模板;
3、创建文档、框架和视类;
4、打开文件;
5、将该文件和档案(CArchive)联系起来;
6、调用Serialize。
而OnFileNew不执行1、2、4、5几步,其他相同。具体的代码可以参考MFC/Src目录中的源程序。
如果你想实现OnFileOpen是为了读你自己定义的文件,一般不重载OnFileOpen,而是在Doc类的Serialize中写代码。如果不习惯CArchive类,也可以直接重载OnOpenDocument(它是Serialize的父函数)。这方面的例子可以参考VC++的diblook。
如果你只是想显示一个与众不同的选择文件的对话框,一般需要重载OnFileOpen。大致的步骤是:
void CYourApp::OnFileOpen()
CString newName;
if(!ShowYourDialog(newName))
return; // 显示你的对话框
OpenDocumentFile(newName);
}
你只需要实现ShowYourDialog(newName)就可以了。
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen与OnOpenDocument
- OnFileOpen 与 OnFileOpenDocument
- CDocument::OnOpenDocument
- CWinApp::OnFileOpen
- CDocument ::OnNewDocument和CDocument :: OnOpenDocument
- OnOpenDocument指定打开文档的默认类型
- OnOpenDocument指定打开文档的默认类型
- MFC OnFileNew OnFileOpen过程分析代码
- MFC OnFileNew OnFileOpen过程分析代码
- MFC MDI OnOpenDocument后自动调用相应的OnDraw
- OnFileNew()/OnFileOpen()的MFC代码跟踪简析
- 创建型:Creational
- 顺序队列的创建、入队、出队
- Asp.net中DataBinder.Eval用法的总结
- sensor各种类以及含义
- 【POJ】1004 Financial Management
- OnFileOpen与OnOpenDocument
- 使用16进制颜色值
- U盘数据突然不显示怎么恢复
- 解析xml实例,包含复杂xml的循环解析
- 程序上传开发机
- 篱笆加密算法
- MYSQL卸载后重装无法start service的解决办法
- PAT A 1074. Reversing Linked List (25)
- 窗口大小屏幕自适应控件ResizeKit