术语 | CDocument::OnOpenDocument | ||
释义 | CDocument::OnOpenDocument virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); 返回值:如果文档装载成功,则返回非零值,否则为0。 参数:
说明: 由框架调用该函数,作为File Open命令的一部分。缺省实现方式是打开指定文件,调用DeleteContents来确保文档是空的,调用CObject::Serialize阅读文件内容,然后标明文档未被修改。如果不使用归档机制或文件机制,则覆盖该函数。例如,应用中的文档表示一个数据库的记录而非文件。 如果用户在SDI应用中选择了File Open命令,框架使用该函数对CDocument对象进行重新初始化,而不是创建一个新的文档。如果用户在MDI应用中选择了File Open命令,框架每次建立一个新的CDocument对象并调用该函数来进行初始化。必须将初始化代码放在这个函数中而不是放在File Open命令的构造程序中,该程序在SDI中有效。 示例: // The following examples illustrate alternative methods of // initializing a document object. // Method 1: In an MDI application,the simplest place to do // initialization is in the document constructor.The framework // always creates a new document object for File New or File Open. CMyDoc::CMyDoc() { // Do initialization of MDI document here. // ... } // Method 2: In an SDI or MDI application,do all initialization // in an override of OnNewDocument,if you are certain that // the initialization is effectively saved upon File Save // and fully restored upon File Open,via serialization. BOOL CMyDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // Do initialization of new document here. return TRUE; } // Method 3: If the initialization of your document is not // effectively saved and restored by serialization(during File Save // and File Open),the implement the initialization in single // function(named InitMyDocument in this example).Call the // shared initialization function from overrides of both // OnNewDocument and OnOpenDocument. BOOL CMyDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; InitMyDocument(); //call your shared initialization function // If your new document object requires additional initialization // not necessary when the document is deserialized via File Open, // then perform that additional initialization here. return TRUE; } 请参阅: CDocument::DeleteContents, CDocument::OnCloseDocument, CDocument::OnNewDocument, CDocument::OnSaveDocument, CDocument::ReportSaveLoadException, CObject::Serialize |
||
随便看 |
|
MFC类库中文详解手册包含4274条MFC类库参考词条,基本涵盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容,是计算机编程的有利工具。