How to Use Edit Controls in MFC

In Microsoft Windows based systems the CEdit class provides the functions of the edit controls in MFC. In a dialog based program some of the important operations can be performed by the CEdit class. Follow these steps to learn how to use edit controls in MFC.

Instructions

    • 1

      Make a MFC AppWizard. This will be used as an executable project in which to communicate with the computer.

    • 2

      Use this application as an SDI/MDI application. Here you can insert dialog as a tool into the SDI/MDI projcts.

    • 3

      Select the edit control option from the controls toolbox. Transfer this option into the dialog box. In the properties section of the dialog box input the identification for the resource as "IDC_EDTEST."

    • 4

      Check the box that converts the number property to 'True" in the "Edit control->Properties->Styles tab" if the edit control only accepts numbers. This allows the CEdit edit control to permit just numbers.

    • 5

      Append a class member with the CEdit for the edit controls. Assume that the variable name is m_Edit.

    • 6

      Set the values in the edit controls by entering the following code: "//Set the value on CEdit CString I_strValue='Test Value to be set ob CEdit"; m_Edit.SetWindowTest(I_strValue); //Get the value from the CEdit control m_Edit.GetWindowText(I_strValue); //This gets the valie into the CString variable I_strValue"

    • 7

      Retrieve and set the value on a DDX enabled CEdit control. Assume the variable name is m_strEdit and enter the following code: "//To set the value on a DDX based CEdit control void DlgName::Setvalue in Edit() { UpdateData(); m_strEdit = "Test Value set for DDX"; UpdateData(FALSE); } //TO get the value on a DDX based CEdit control void DIgName:: GetvalueFromEdit() { UpdateDate(); CString strStoreValue; strStoreValue = m_strEdit ; UpdateData(FALSE); }"

Related Searches:

Comments

You May Also Like

Related Ads

Featured