Gets a few ways to get the contents of the edit box control.
1.GetDlgItem gets a pointer to the text edit box to get the content. 1
2. Use the GetDlgItemText function to get the contents of the text box ... 1
3. Use Getdlgitemint to get the numeric content directly. 2
4. The fourth method associates the control with a defined variable in the class. 2
5. The fifth uses SendMessage to get the contents of the edit box ... 3
1.GetDlgItem get The text edit box pointer to get the content
Use GetDlgItem (the ID of the edit box) to get a pointer to the edit box first.
The GetWindowText function, which points to the edit box, saves the obtained content to the specified character array.
Here is the code.
int num1,num2,num3; Char char1[10],char2[10],char3[10]; GetDlgItem (IDC_EDIT1)->getwindowtext (char1,10); GetDlgItem (idc_edit2)->getwindowtext (char2,10); Num1=atoi (CHAR1); Num2=atoi (CHAR2); NUM3=NUM2+NUM1; Itoa (num3,char3,10); GetDlgItem (IDC_EDIT3)->setwindowtext (CHAR3); |
2 . Use the GetDlgItemText function to get the contents of the text box.
GetDlgItemText function from the code analysis, the GetDlgItemText function is a shorthand version of the first method.
int num1,num2,num3; Char char1[10],char2[10],char3[10]; GetDlgItemText (idc_edit1,char1,10); GetDlgItemText (idc_edit2,char2,10); Num1=atoi (CHAR1); Num2=atoi (CHAR2); NUM3=NUM2+NUM1; Itoa (num3,char3,10); Setdlgitemtext (IDC_EDIT3,CHAR3); |
3 . use Getdlgitemint to get the numeric content directly.
The second example is to get the text content, to turn into the value of the content, you have to use the Atoi function is more troublesome to use getdlgitemint to directly obtain the value of the content.
The code is as follows
int num1,num2,num3; Char char1[10],char2[10],char3[10]; Num1=getdlgitemint (IDC_EDIT1); Num2=getdlgitemint (IDC_EDIT2); num3=num1+num2; Setdlgitemint (IDC_EDIT3,NUM3); |
4. The fourth method associates the control with a defined variable in the class
Click View-Build Class Wizard-member variables tab click the name of the corresponding control IDs
In member variable name, fill in a variable name.
If you want to take a value directly, select value in the category, then the variable name is the corresponding value
updatedata (); m_edit3=m_edit1+m_edit2; UpdateData (false); |
You can select a data type to define the data type of the variable.
If it's text-based.
Select control in the category, then the variable name corresponds to the control. Use this variable name to manipulate it.
int num1,num2,num3; Char char1[10],char2[10],char3[10]; M_the_edit1. GetWindowText (char1,10); M_the_edit2. GetWindowText (char2,10); Num1=atoi (CHAR1); Num2=atoi (CHAR2); num3=num1+num2; Itoa (num3,char3,10); M_the_edit3. SetWindowText (CHAR3); |
5. The fifth uses SendMessage to get the contents of the edit box.
Use the way messages are sent.
(1). The SendMessage of the global class is used to send the contents of the message.
Note that the first parameter is a handle to the target window control, the second parameter is a fixed identifier, the third is the size of the fourth character variable, and the fourth is a pointer to the array of character variables.
:: SendMessage (GetDlgItem (IDC_EDIT1)->m_hwnd,wm_gettext,10, (LPARAM) char1); |
The
can also be used to get a handle.
:: SendMessage (m_the_edit1.m_hwnd,wm_gettext,10, (LPARAM) char1); |
(2). There are also SendMessage functions in the window class.
GetDlgItem (idc_edit1)->sendmessage (wm_gettext,10, (LPARAM) char1); |
Or so
M_the_edit1. SendMessage (wm_gettext,10, (LPARAM) char1); |
There are also easy-to-senddlgitemmessage functions that can be sent directly to get the text of the message that refers to the specified control's ID.
SendDlgItemMessage (Idc_edit2,wm_gettext, (LPARAM) char2); |