Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Edit Control MFC vc++

Edit Control MFC vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
13 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14575556
    wrote on last edited by
    #1

    I'm trying to make something like this. In the edit control when I input some number other than the default number immediately some warning will be displayed. e.g. there are 3 bottle which have the capacity of 1L, 2L & 3L resp. When I type 2 for the 1st bottle immediately I want to display warning message below. I need some guidance to achieve this. Thank you. P.s. I would be very grateful if some example is given. :)

    L _ 3 Replies Last reply
    0
    • M Member_14575556

      I'm trying to make something like this. In the edit control when I input some number other than the default number immediately some warning will be displayed. e.g. there are 3 bottle which have the capacity of 1L, 2L & 3L resp. When I type 2 for the 1st bottle immediately I want to display warning message below. I need some guidance to achieve this. Thank you. P.s. I would be very grateful if some example is given. :)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The same as the answer to your question below on validating edit controls.

      1 Reply Last reply
      0
      • M Member_14575556

        I'm trying to make something like this. In the edit control when I input some number other than the default number immediately some warning will be displayed. e.g. there are 3 bottle which have the capacity of 1L, 2L & 3L resp. When I type 2 for the 1st bottle immediately I want to display warning message below. I need some guidance to achieve this. Thank you. P.s. I would be very grateful if some example is given. :)

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        As Victor said, the simple way to achieve this task is to use CEdit Class | Microsoft Docs | ShowBalloonTip[^]

        M 1 Reply Last reply
        0
        • _ _Flaviu

          As Victor said, the simple way to achieve this task is to use CEdit Class | Microsoft Docs | ShowBalloonTip[^]

          M Offline
          M Offline
          Member_14575556
          wrote on last edited by
          #4

          in .h file :

          afx_msg void MyDlg::OnEnChangeEdit();

          in .cpp file :

          BEGIN_MESSAGE_MAP(MyDlg, CDialogEx)
          ON_EN_CHANGE(IDC_EDIT2, &MedicationDlg::OnEnChangeEdit)
          END_MESSAGE_MAP()

          void MyDlg :: OnEnchangeEdit()
          {
          CString temp;
          //could you give some some direction on how to get the text entered in the edit control
          // Should I use the control value variable of the edit control to save the input
          // I am confused here, I would like some direction. Thanks
          updateData(TRUE);
          temp = m_editvariable;

          Function(1st parameter, temp) // this function will check the text entered in the edit control, with the default value and display appropriate message
          }

          Thanks.

          _ 1 Reply Last reply
          0
          • M Member_14575556

            in .h file :

            afx_msg void MyDlg::OnEnChangeEdit();

            in .cpp file :

            BEGIN_MESSAGE_MAP(MyDlg, CDialogEx)
            ON_EN_CHANGE(IDC_EDIT2, &MedicationDlg::OnEnChangeEdit)
            END_MESSAGE_MAP()

            void MyDlg :: OnEnchangeEdit()
            {
            CString temp;
            //could you give some some direction on how to get the text entered in the edit control
            // Should I use the control value variable of the edit control to save the input
            // I am confused here, I would like some direction. Thanks
            updateData(TRUE);
            temp = m_editvariable;

            Function(1st parameter, temp) // this function will check the text entered in the edit control, with the default value and display appropriate message
            }

            Thanks.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            What kind of object is m_editvariable ?

            M 1 Reply Last reply
            0
            • _ _Flaviu

              What kind of object is m_editvariable ?

              M Offline
              M Offline
              Member_14575556
              wrote on last edited by
              #6

              I have edited like the below code. Only the first character I type shows in message box. What I wanted was the whole thing i type in the edit control. eg. when I try to enter 300, the moment i type 3 message pop up with 3.

              void MyDlg::OnEnChangeEdit()
              {
              CString temp;
              m_Edit.GetWindowTextW(temp); // CEdit m_Edit;
              MessageBox(temp);

              Function(1st parameter, temp);
              

              }

              _ D 2 Replies Last reply
              0
              • M Member_14575556

                I have edited like the below code. Only the first character I type shows in message box. What I wanted was the whole thing i type in the edit control. eg. when I try to enter 300, the moment i type 3 message pop up with 3.

                void MyDlg::OnEnChangeEdit()
                {
                CString temp;
                m_Edit.GetWindowTextW(temp); // CEdit m_Edit;
                MessageBox(temp);

                Function(1st parameter, temp);
                

                }

                _ Offline
                _ Offline
                _Flaviu
                wrote on last edited by
                #7

                You can associate a CString value with your edit control, and there you will have entire edit value. VS wizzard allow you to do that.

                M 1 Reply Last reply
                0
                • _ _Flaviu

                  You can associate a CString value with your edit control, and there you will have entire edit value. VS wizzard allow you to do that.

                  M Offline
                  M Offline
                  Member_14575556
                  wrote on last edited by
                  #8

                  Could you give an example. Thanks

                  _ 1 Reply Last reply
                  0
                  • M Member_14575556

                    Could you give an example. Thanks

                    _ Offline
                    _ Offline
                    _Flaviu
                    wrote on last edited by
                    #9

                    In header:

                    public:
                    //{{AFX_DATA(MyDlg)
                    enum { IDD = IDD_TEST_FORM };
                    CEdit m_Edit1;
                    CString m_sEdit1;
                    //}}AFX_DATA

                    in cpp:

                    void MyDlg::DoDataExchange(CDataExchange* pDX)
                    {
                    CDialog::DoDataExchange(pDX);
                    //{{AFX_DATA_MAP(MyDlg)
                    DDX_Control(pDX, IDC_EDIT1, m_Edit1);
                    DDX_Text(pDX, IDC_EDIT1, m_sEdit1);
                    //}}AFX_DATA_MAP
                    }

                    so you have the value of edit control inside of m_sEdit1. Example:

                    void MyDlg::OnEnchangeEdit()
                    {
                    updateData(FALSE);
                    Function(1st parameter, m_sEdit1);
                    }

                    M 1 Reply Last reply
                    0
                    • _ _Flaviu

                      In header:

                      public:
                      //{{AFX_DATA(MyDlg)
                      enum { IDD = IDD_TEST_FORM };
                      CEdit m_Edit1;
                      CString m_sEdit1;
                      //}}AFX_DATA

                      in cpp:

                      void MyDlg::DoDataExchange(CDataExchange* pDX)
                      {
                      CDialog::DoDataExchange(pDX);
                      //{{AFX_DATA_MAP(MyDlg)
                      DDX_Control(pDX, IDC_EDIT1, m_Edit1);
                      DDX_Text(pDX, IDC_EDIT1, m_sEdit1);
                      //}}AFX_DATA_MAP
                      }

                      so you have the value of edit control inside of m_sEdit1. Example:

                      void MyDlg::OnEnchangeEdit()
                      {
                      updateData(FALSE);
                      Function(1st parameter, m_sEdit1);
                      }

                      M Offline
                      M Offline
                      Member_14575556
                      wrote on last edited by
                      #10

                      Thank you . The example really really helps. :)

                      1 Reply Last reply
                      0
                      • M Member_14575556

                        I have edited like the below code. Only the first character I type shows in message box. What I wanted was the whole thing i type in the edit control. eg. when I try to enter 300, the moment i type 3 message pop up with 3.

                        void MyDlg::OnEnChangeEdit()
                        {
                        CString temp;
                        m_Edit.GetWindowTextW(temp); // CEdit m_Edit;
                        MessageBox(temp);

                        Function(1st parameter, temp);
                        

                        }

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        Member 14575556 wrote:

                        m_Edit.GetWindowTextW(temp);

                        Why not just use GetWindowText()?

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        M 1 Reply Last reply
                        0
                        • D David Crow

                          Member 14575556 wrote:

                          m_Edit.GetWindowTextW(temp);

                          Why not just use GetWindowText()?

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          M Offline
                          M Offline
                          Member_14575556
                          wrote on last edited by
                          #12

                          It was a typo. I've changed it. Thanks :)

                          1 Reply Last reply
                          0
                          • M Member_14575556

                            I'm trying to make something like this. In the edit control when I input some number other than the default number immediately some warning will be displayed. e.g. there are 3 bottle which have the capacity of 1L, 2L & 3L resp. When I type 2 for the 1st bottle immediately I want to display warning message below. I need some guidance to achieve this. Thank you. P.s. I would be very grateful if some example is given. :)

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            Use 3 radio buttons; default select the first option (1L). Or leave it "empty" (tri-state) and warn if no selection made. Standard stuff that everyone recognizes.

                            The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups