CFormView is used almost like CDialog. The DDX and DDV work the same way, with a
call to UpdateData(TRUE) whenever you want the member variables updated with
data from the controls. When data is input into any of the edit boxes, we must
provide the code, which inserts the values from the controls into the view’s
member variables. We must also provide code to then transfer the data into the
document class.
The UpdateData(FALSE) should be called, when ever we want the data to be
transferred from the view’s member variables into the edit controls. In the
OnUpdate() function of CFormView class inherited from the CView, the data is
transferred from the document to the view’s member variables. Then to transfer
the data from the variables into the edit boxes, we must explicitly call the
function UpdateData(FALSE).
In these handler functions, we must also keep track of when the data has been
modified by the user. If at any time the data in the document is modified, we
set a “dirty bit” in the document class by calling CDocument::SetModifiedFlag().
This will enable MFC to notify the user that the document needs to be saved if
the user tries to quit the application, close the document, or open another
document. This bit is cleared automatically when the document is saved.
|