MFC advanced course in layman's language version. Notes Day 4

 

Usually have no access to the MFC code, this is the project dictates, the project involves hands MFC, feeling a bit mean, so looking at the video to learn b station, had not started operating, just fly, a general understanding of this flow of the code, now offer video link station b: MFC advanced course in layman's language version of the
following is the course notes:

[According to the wizard, create a single document engineering]
the fourth day (and view documents, database programming):
    1, view the document describes the structure
    2, use CArchive class
    3, MFC odbc to operate the database
 open database connect
 
 

First, the document view structure

Document class (CDocument): Load memory (read and write) data
view class (CView): displaying the data

1) single document
 a) a document template: app Initinstance document template in the window frame, document, associated with view
 b) document class (CDocument):
  OnNewDocument (), first call the new window, behind each time you press the "New" called
  DeleteContents (), the release of resources to do some operations, each time you press the "New" first call before New this function
 c) is a view of the frame class may be considered a container class

2) various related access
 a) in the view class view, how the document object pointer to access the GetDocument :: CView
 the CDocument the GetDocument * () const;
 as:
 void xxx_View the OnDraw :: ( * the CDC / * the pDC * /)
 {
  xxx_Doc * pDoc the GetDocument = ();
 }

 
the CFile:
Write-Store
Read-Load
the MFC Chinese Manual :: the Open the CFile
the CArchive no base class, directly check MSDN

Second, the document serialization (binary operation file CArchive) is equivalent to Qt QDataStream

Serialization: Serialization is the actual file read and write

serialization: write files in binary mode
deserialize: read files in binary mode

1) write files
 a) create a file object CFile
 b) open a file for writing :: Open CFile
 c) create a sequence of objects and documents and associated with the CArchive
  the CArchive :: Store to save the data to an archive file. CFile allow write operations.
 d) write data to data stream (corresponding to write data to the file, sequentially)
  Ar << << A << B C
 E) and disconnect the data stream files associated with the Close :: the CArchive
 F) CFile :: Close closes the file

2) read the file
 a) creating a file object the CFile
 B) open the file for reading the open :: the CFile
 C) to create a serialized object, and associated with the file, and the CArchive
    the CArchive :: load load data from the archive. CFile read-only.

Third, the document view case

1) document class serialization function comes the Serialize ()
 void CMy01_ :: CArchiveDoc the Serialize (the CArchive & Ar)
 {
  IF (ar.IsStoring ())
  {
   // the TODO: this addition is stored in the code
   // press Save button calls
   / / when you click save, the system automatically generates a file that bind and ar
  }
  the else
  {
   // TODO: add loading code here
   // press the open button to call
  }
 }

2) student management system
 a) define a student class Stu
  CList < * STU> list;
 B) for storing data doc document class, view class view and modify the display data
  1) additive element from the end CList :: AddTail
  2) Get a list of the location of trailing elements :: GetTailPosition CList
  . 3) obtaining an element CList: : GetPrev
  4) to get the next element :: GetNext CList
  5) get the first element position :: GetHeadPosition CList
  6) Gets the last element position CList :: GetTailPosition
  7) Get the specified location :: GetAt element CList
  . 8) element of the head node is removed (no free space) CList :: RemoveHead
 base class c) are views of the CFormView
 D) rewritable document class DeleteContents (), do some release operating resources, each time you press the "New", call this function before New

Fourth, database programming

1) Preparation
  a) mounting MySQL server
  B) driving MySQL odbc
 
2) odbc hierarchical graph
  a) a set of standard interfaces odbc (sql statement by the internal operation of the database, even if the user may not understand the sql statement by odbc database operation)
  B) data source
   
3) how to create a data source (MySql only snapshots)
  A) snapshot (snapshot) record sets: update after every operation to re-query
  b) dynamic (Dynaset) record sets: each operation is automatically updated (add foreign record)

4) application framework
 a) CRecordset subclass, mainly the database corresponding operation
  1) DoFieldExchange () automatically fields and variables associated database
  2) GetDefaultConnect () database connection information
  3) GetDefaultSQL () get a database connection table
 b) the CFormView subclass, the display contents of the database view
  1) OnInitialUpdate () primarily for initialization function

5) corresponding operations on the database by the CRecordset class
 a) the view class header file created CRecordset subclass objects
 b) view class do CRUD operations
  1) to open the open database :: the CRecordset
  2) query log CRecordset :: Requery
  3) moving a recording current CRecordset :: MovePrev
  4) moving a record set the MoveNext CRecordset ::
  . 5) whether the next last record CRecordset IsEOF ::
  . 6) whether the first record on a CRecordset :: IsBOF
  . 7) moves to the first recording the MoveFirst :: CRecordset
  . 8) moves to the last record the MoveLast :: CRecordset
  . 9) add an empty record the AddNew :: CRecordset
  10) may be modified if the recordset :: CanUpdate CRecordset
  . 11) to update the record set CRecordset the Update ::
  12 is) :: the delete deletes the current record the CRecordset
  13 is) :: edit the edit current record the CRecordset
  14) :: m_strFilter filter the CRecordset
  15) Sort CRecordset :: m_strSort (default ascending, descending plus desc)
 C) Precautions
  1) movement record collection, processing across the border
  after 2) mobile recording set, do not re-query, the query is equivalent to re-start again cursors

Guess you like

Origin www.cnblogs.com/yeyeye123/p/11032301.html