Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
Practical Learning: Checking Control Variables
- Open the Quadrilateral.cpp file and check the DoDataExchange event:
void CQuadrilateral::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDT_SSIDE, m_SquareSide);
DDX_Control(pDX, IDC_EDT_SPRM, m_SquarePerimeter);
DDX_Control(pDX, IDC_EDT_SAREA, m_SquareArea);
DDX_Control(pDX, IDC_EDT_RLENGTH, m_RectLength);
DDX_Control(pDX, IDC_EDT_RHEIGHT, m_RectHeight);
DDX_Control(pDX, IDC_EDT_RPRM, m_RectPerimeter);
DDX_Control(pDX, IDC_EDT_RAREA, m_RectArea);
}
- Save All
14.1.4..Control’s Value Variables..................................................................
Another type of variable you can declare for a control is the value variable. Not all
controls provide a value variable. The value variable must be able to handle the type of
value stored in the control it is intended to refer to. For example, because a text-based
control is used to handle text, you can declare a text-based data type for it. This would
usually be a CString variable. Here is an example:
class CExchangeDlg : public CDialog
{
...
public:
CStatic stcAdvanced;
CString strFullName;
};
On the other hand, as we will learn that some controls handle a value that can be true or
false at one time, namely the check box, you can declare a Boolean variable for such
controls. Some other controls are used to hold a numeric value such as a natural or a
floating-point number. You can declare an integer-based or a float-based value variable
for such controls. Some other controls are not meant to hold an explicit or recognizable
type of data, an example would be the tab control. For such controls, there is no value
variable available. For such controls, you can only declare a control variable.
After declaring the value variable, as done with the control variable, you must “map” it to
the intended control. To do this, you must call an appropriate framework function. The
functions are categorized based on the type of data held by the variable. For example, if
the control holds text and you had declared a CString value variable for it, you can call
the DDX_Text() function to map it. The DDX_Text() function is provided in various
versions as follows:
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, BYTE& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, short& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, int& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, UINT& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, long& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, DWORD& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, CString& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, float& value );