Problem: use MFC Appwizard *. in the multi-document view structure program generated by EXE, When you click the open item in the File menu, the program will call the cwinapp: onfileopen function of the application class, what actions have this function performed in order? This is the same as when you click New to call the cwinapp: What are the differences between the functions executed by the onfilenew function?
Cwinapp: The onfileopen function performs the following steps:
1. prompt the user to select a file;
2. Select a matching file template;
3. Create documents, frameworks, and visual classes;
4. open the file;
5. Associate the file with the file (carchive;
6. Call serialize.
Onfilenew does not perform steps 1, 2, 4, or 5. The other steps are the same. For specific code, refer to the source program in the MFC \ src directory.
If you want to implement onfileopen to read your own defined files, do not reload onfileopen, but write code in serialize of the doc class. If you are not used to the carchive class, you can directly overload onopendocument (which is the parent function of serialize ). For this example, see diblook of VC ++.
If you only want to display a dialog box with a unique file selection, you generally need to reload onfileopen. The general steps are as follows:
Void cyourapp: onfileopen ()
Cstring newname;
If (! Showyourdialog (newname ))
Return; // display your dialog box
Opendocumentfile (newname );
}
You only need to implement showyourdialog (newname ).
Original article: http://www.china-askpro.com/msg39/qa21.shtml
1. Create a document
On_command (id_file_new, cwinapp: onfilenew)
Entry: cwinapp: onfilenew
Call: cdocmanager: onfilenew ()
1. Determine whether a document template exists. If no template exists, the function returns;
2. Determine whether there are multiple document templates. If yes, enable the Document Template Selection dialog box. After selecting a template, return the template pointer.
3. Access cmultidoctemplate by template pointer: opendocumentfile ()
31. Create a New Document Object
32. Create a sub-framework corresponding to the new document object to build the sub-framework, the relationship between the document and the window
33. Call the onnewdocument () of the application ()
A. Call cdocument: onnewdocument ()
Call deletecontents () of the application ();
B. User code
34. Call initialupdateframe () display window
35. Return document pointer
4. Return
2. Open the document
On_command (id_file_open, cwinapp: onfileopen)
Entry: cwinapp: onfileopen
Call: cdocmanager: onfileopen ()
1. In the dialog box that appears, select the file to be opened and return the full path name of the file for the following function calls.
2. Call the opendocumentfile (lpctstr lpszfilename) of the application)
21. User code
22. Call cwinapp: opendocumentfile (lpszfilename ),
Call cwinapp: opendocumentfile (lpszfilename ),
Call cdocmanager: opendocumentfile
A. Check whether the file has been opened. If yes, activate the window and return
B. Call cmultidoctemplate: opendocumentfile ()
B1. create a new document object and a sub-framework corresponding to the new document object
B2. call the onopendocument () of the application ()
(1) Call cdocument: onopendocument ()
. Open the file object
. Call deletedontents () of the application ();
. Create a carchive object associated with this file object
. Call the serialize () function of the application document object
. Close the carchive object and file object.
(2) display the file window
B3. return
Iii. File Storage
On_command (id_file_save, cdocument: onfilesave)
Entry: cdocument: onfilesave ()
Call: cdocument: dofilesave ()
If the file name corresponding to the current document is null or a read-only file, call cdocument: dosave (null) with null as the parameter. Otherwise, call cdocument: with the corresponding file name as the parameter :: dosave (m_strpathname );
On_command (id_file_saveas, cdocument: onfilesaveas)
Entry: cdocument: onfilesaveas ()
Use null as the parameter to directly call cdocument: dosave (null );
Cdocument: dosave (lpctstr lpszpathname, bool breplace );
If lpszpathname is null,
1. Set the default file name of the application
2. Open the universal file storage dialog box, set the name of the file to be saved, and return the file name.
If lpszpahtname is not null, skip the preceding two steps and go directly to the next step.
3. Call the application's onsavedocument ()
31. User code
32. Call cdocument: onsavedocument ()
A. Create or open a file object
B. Create the corresponding carchive object
C. Call the serialization function serialize () of the application documentation object ()
D. close the file object and carchive object
E. Set the file flag not modified
4. Return
Original article: http://topic.csdn.net/t/20001213/18/48208.html