Obtaining and assigning the Edit Control Value in MFC

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.