术语 | CDocument::OnNewDocument |
释义 | CDocument::OnNewDocument virtual BOOL OnNewDocument(); 返回值:如果文档初始化成功,则返回非零值,否则为0。 说明: 由框架调用,作为File New命令的一部分。缺省实现方式是调用该函数确保文档为空,并标明新文档是未被修改的。覆盖该函数进行新文档数据结构的初始化,应从函数覆盖中调用该函数的基类版本。 如果用户在SDI应用中选择了File New命令,框架使用该函数对存在的文档进行重新初始化,而不是创建一个新的文档。如果用户在MDI应用中选择了File New命令,框架每次建立一个新的文档并调用该函数来进行初始化。必须将初始化代码放在这个函数中而不是放在FileNew命令的构造程序中,该程序在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 override 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::CDocument, CDocument::DeleteContents, CDocument::OnCloseDocument, CDocument::OnOpenDocument, CDocument::OnSaveDocument |
随便看 |
|
MFC类库中文详解手册包含4274条MFC类库参考词条,基本涵盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容,是计算机编程的有利工具。