Edit Control is one of the most frequently used controls in the MFC dialog box. It is a common operation to obtain Edit Control and assign values. Let's take a look at how to implement it. IDE Visual Studio 2010, MFC project.
First, create an MFC project.
In the resource view interface, open IDD_NOWAMAGIC_MFC_DIALOG in the Dialog folder and design the interface as follows:
Select Edit Control, click the lightning icon in the attribute bar, and select BN_CLICKED to add the OnBnClickedOk event.
Void CNowaMagic_MFCDlg: OnBnClickedOk () {// TODO: add control notification handler code here}
We can rewrite this method to get the value from Edit Control and output it through MessageBox.
Void CNowaMagic_MFCDlg: OnBnClickedOk () {// TODO: add the control notification handler code here // CDialogEx: OnOK (); // obtain EDIT CEdit * pBoxOne; pBoxOne = (CEdit *) GetDlgItem (IDC_EDIT1); // value assignment // pBoxOne-> SetWindowText (_ T ("FOO"); // value: CString str; pBoxOne-> GetWindowText (str); MessageBox (str, _ T ("program running result"), MB_ OK); str. releaseBuffer ();}
OK, that's simple. The following is the execution: