Example // 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), then 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; }
好象不行哦
// 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), then 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;
}
C++没学好!~
一般调文档模板去打开一个文档,会自动调用这个函数,并生成相应的框架类和视图类。
onnewdocument应该是受保护的,你直接去调当然调不了。