Reading notes 5

xiaoxiao2021-03-06  118

MFC Program - Document / View Supported Window Program Principle (OK, HEHE), after File / New or File / Open, generate DOC and View's processes (see also follow-up SERIALIZE ()): 1) CWINAPP Select appropriate DOCTEMPLATE; 2) Construct CDOC .. Object (CMYDOC); 3) Construct CFrame .. window object (cchildframe); 4) Generate a Frame window, generate message wm_create; 5) cframe .. :: oncreate, construct the Frame object, generate View window; 6) If it is file / open, you have to read the file, initialize the view, display information in View;

Serialize () mechanism (1) Serialize () is the object-oriented (OO) world in the persistence, the object is to survive, of course, they must be retained in the file, and when the program is activated, it can dynamically identify, dynamically create This is the so-called serialize (). Overall, the serialize () operation is a process of gradually refining from top, such as cdoc .. :: serialize () -> carchive << CMYOBJECT ("<<" is overloaded) -> carray :: serialize () / CList :: serialize () / cmap :: serialize () -> CPoint / CRECT / CSIZE / CSTRING read and write, some steps are not necessary, and when Serialize certainly cannot miss carchive. Explain the file write operation of Serialize (): 1) file / save as triggered CDocument :: onfilesaves (Message mechanism, later); 2) cdocument :: onfilesaves call cdocument :: DOSAVE; 3) CDocument :: DOSAVE call cdocument: : OnSaveDocument, the save as dialog is generated; 4) CDocument :: OnSaveDocument call cdocument :: serialize (), must be associated with the CFILE object with the CFile object before the call; 5) The virtual function serialize () is overloaded by CMYDOC, Complete your own write operation, pick up the example: CMYDOC :: serialize () call ar << POB (ar "of CARCHIVE object, << is overloaded, POB is a CMYObject pointer); 6) Tune Ar.WriteObject POB); 7), where the CRUNTIMECLASS data is obtained, including such related information, and generating such function pointers to create this type of function pointer; 8), then call Ar.WriteClass, implement write class In the file, the specific process is as follows: 9) If the new class is output, the FFFF is output, and the class number (there is record in this CRUntimeClass object), such version information, this type of name; if not new Class, only one identified number is output to prevent redundancy, space saving and reading and writing time; 10), output the specific data of the class, such as CPoint / CRECT / CSIZE / CSTRING and basic data type data, etc. It is specific to the specific situation, and the member function under Ar is generally invoked.

Serialize () mechanism (2) SERIALIZE () file read operation: 1) CWINAPP: ONFILEOPEN Intercept file / open command message; 2) cwinapp :: onfileopen call cdocmanager :: onfileopen, the latter call cwinapp :: OpenDocumentfile, the latter and calls CDocmanager :: OpenDocumentFile, the latter tune has CDocTemplate :: OpenDocumentFile (CDocTemplate debut), in addition, CDocManager responsible for generating CDocTemplate object, and find the best Template into this object from Doc Template chain; 3) CDocTemplate :: OpenDocumentFile generates a new DOC, a new window, calls as follows: 4) CDocument :: CreateNewDocument generates a new DOC, CDocument :: CreateNewFrame new window, the process has been said in the premises; 5) After it (CDOCTemplate :: OpenDocumentFile call CMYDOC :: OpenDocument, the latter is associated with the CFILE and CARCHIVE objects, and call serialize (); 6) The process is the same, but it is only reading, of course, it is heavy. >>, special attention Take the dynamic creation of the object is a function pointer under its CRUNTIMECLASS object. In addition, in serialize (), it is read is written (ISSE () mechanism (3), I want to say that Serialize requirements: 1) Class is generally derived from COBJECT, there is Declaration Macro Declare_Serial and Implement Macro Implement_Serial, so that the previous dynamic identification, dynamic creation, of course, the most important thing is what the Persistence function is here, because "macro" is in the ghost, this is also MFC So it seems a complicated reason, see the file AFX.H. 2) SERIALIZE () must be overloaded, so that you can complete a specific function; 3) There must be a default constructor in the class, because the front is not a CRUNTIMECLASS object in the class, where there is a function pointer to create an object The dynamic creation here is that the default of the call is in the function, as for this CruntimeClass, which is also passed by 1), and of course, CruntimeClass also has a function in a so-called dynamic type identification, and is the main role, huh, ! Also, talk about serialize () It is necessary to talk about Carchive, because the SERIALIZE object is a CARCHIVE object, and he is simple to be a memory buffer associated with the file, and his association with the file is as mentioned above. CARCHIVE's key operation is the overloading of << and >> is not detailed. If you are interested, please see the AFX.INL file.

转载请注明原文地址:https://www.9cbs.com/read-98436.html

New Post(0)