Game Development Reference
In-Depth Information
Figure B.7 Setting the function name.
NUM1 occurs, this function gets called. In the 'Examples/AppendixB/
MFCDialog' folder on the CD you will find this project. This project has
functions for both IDC_NUM1 and IDC_NUM2. For each of these we will
look at how to get at the control data. If you have created member
variables for the controls then you can load the control data into these
member variables using the function UpdateData(TRUE) . By passing
TRUE to this function you are transferring the control data to your
variables. In this simple example, we get the two numerical values, add
them together and store the result in the member variable m_result . In the
project m_result maps to the control IDC_NUM3, which we use to display
the result. To transfer the value in the variable m_result into the control
IDC_NUM3, we can use UpdateData(FALSE) . By passing FALSE to this
function the tied variable value is transferred into the control.
void CMFCDialogDlg::OnChangeNum1()
//Get values of m_num1 and m_num2 from the controls
m_result = m_num1 + m_num2;
//Put the sum, m_result, into the control IDC_NUM3
If we had not used tied member variables we could still get the data out
of the control. All controls are derived from the class CWnd . This class has
a member function GetWindowText . The Dialog class CDialog has a
member function GetDlgItem . Passing the ID of the control to GetDlgItem
returns a pointer to a CWnd . We can use this pointer and the function
GetWindowText to retrieve the text in the control. We convert the text into
a number, repeat for the second number and then sum the result. We
convert the sum into a string using another MFC class, CString . This class
Search Nedrilad ::

Custom Search