Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls



  1. Also test the calculations of the 3-Dimensions property page

  2. After using it, close the application and return to MSVC


14.2.7..Controls Values Update......................................................................


The controls used in your application are designed to work as an ensemble, exchanging
data with one another and with the window that hosts them. For their various operations
to work, the dialog-based object that is hosting the controls needs to be able to update
their values. If you are using control variables, because these controls are based on
CWnd, they can perform their own validations.

If you are using value controls, and if the user must be able to change the values held by a
dialog’s controls, you can decide how and when the values should be updated by the
parent window. This can be done by calling the CWnd::UpdateData() method. Its
syntax is:

BOOL UpdateData(BOOL bSaveAndValidate = TRUE);

The bSaveAndValidate argument specifies whether the parent window, usually a dialog-
based object, must update the values of variables at the time this method is called. This
member variable works in conformance with the CDialog::DoDataExchange() event of
the dialog that owns the controls. If it is called with no argument or the TRUE default
value, this indicates that the dialog is ready to communicate with the variables mapped in
DoDataExchange(). After such a call, you can let the user do what is necessary on the
controls. When this method is called a FALSE value for the bSaveAndValidate argument,
it indicates that the dialog box can take ownership of operations and the controls have
stopped updating their information.You can handle this when the user clicks a button
such as Submit or OK after changing values on controls. Normally, the call with a
FALSE argument means that the dialog box is being either initialized or reinitialized,
which is done when its OnInitDialog() event fires.
Free download pdf