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. EN_CHANGE and CEdit, simple question

EN_CHANGE and CEdit, simple question

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 4 Posters 0 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.
  • N Offline
    N Offline
    ns
    wrote on last edited by
    #1

    A dilemma: I want a "done" button to be disabled until the user adds omething to the CEdit. Fine. I trapped the EN_CHANGE, and the button comes alive as soon as the user enters anything. Problem is, I dont ever want this field to be empty, and if after typing a letter in, the user goes back and deletes it, my "done" button is still enabled. It should only be enabled when theres something in the CEdit. How do I do this? ====================================================================================== My other tactic was to test when the "done' was pressed like this(below) but it freezes my program and doesnt give me a chance to enter something into the CEdit:

    void CDlgMineName::OnButtonDone()
    {

    CString UserEntry;
    
    m\_editMineName.GetWindowText(UserEntry);
    
    while (UserEntry =="")
    {
    	m\_editMineName.SetFocus();
    
    	m\_editMineName.GetWindowText(UserEntry);`why cant I enter anything here?` 
    }
    
    It freezes  and I have to kill it from task manager. Is it obvious why ?
    

    Thanks, ns

    T R S 3 Replies Last reply
    0
    • N ns

      A dilemma: I want a "done" button to be disabled until the user adds omething to the CEdit. Fine. I trapped the EN_CHANGE, and the button comes alive as soon as the user enters anything. Problem is, I dont ever want this field to be empty, and if after typing a letter in, the user goes back and deletes it, my "done" button is still enabled. It should only be enabled when theres something in the CEdit. How do I do this? ====================================================================================== My other tactic was to test when the "done' was pressed like this(below) but it freezes my program and doesnt give me a chance to enter something into the CEdit:

      void CDlgMineName::OnButtonDone()
      {

      CString UserEntry;
      
      m\_editMineName.GetWindowText(UserEntry);
      
      while (UserEntry =="")
      {
      	m\_editMineName.SetFocus();
      
      	m\_editMineName.GetWindowText(UserEntry);`why cant I enter anything here?` 
      }
      
      It freezes  and I have to kill it from task manager. Is it obvious why ?
      

      Thanks, ns

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      ns wrote: I trapped the EN_CHANGE, So EN_CHANGE isn't sent when user deletes text from edit control? Tomasz Sowinski -- http://www.shooltz.com

      Free your mind and your ass will follow.

      N 1 Reply Last reply
      0
      • N ns

        A dilemma: I want a "done" button to be disabled until the user adds omething to the CEdit. Fine. I trapped the EN_CHANGE, and the button comes alive as soon as the user enters anything. Problem is, I dont ever want this field to be empty, and if after typing a letter in, the user goes back and deletes it, my "done" button is still enabled. It should only be enabled when theres something in the CEdit. How do I do this? ====================================================================================== My other tactic was to test when the "done' was pressed like this(below) but it freezes my program and doesnt give me a chance to enter something into the CEdit:

        void CDlgMineName::OnButtonDone()
        {

        CString UserEntry;
        
        m\_editMineName.GetWindowText(UserEntry);
        
        while (UserEntry =="")
        {
        	m\_editMineName.SetFocus();
        
        	m\_editMineName.GetWindowText(UserEntry);`why cant I enter anything here?` 
        }
        
        It freezes  and I have to kill it from task manager. Is it obvious why ?
        

        Thanks, ns

        R Offline
        R Offline
        Roger Allen
        wrote on last edited by
        #3

        For the EN_CHANGE you would just write

        CString name ;
        m_editMineName.GetWindowText(name) ;
        GetDlgItem(IDC_BUTTON_DONE)->EnableWindow(name.GetLength() > 0) ;

        Roger Allen Sonork 100.10016 I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.

        N 1 Reply Last reply
        0
        • T Tomasz Sowinski

          ns wrote: I trapped the EN_CHANGE, So EN_CHANGE isn't sent when user deletes text from edit control? Tomasz Sowinski -- http://www.shooltz.com

          Free your mind and your ass will follow.

          N Offline
          N Offline
          ns
          wrote on last edited by
          #4

          It probably is, but heres what I do in the function:

          void CDlgMineName::OnChangeEditminename()
          {

          m\_buttonminename.EnableWindow(TRUE);
          

          }

          If the change was of a "negative type" i.e. nothings left in the CEdit, I want to EnableWindow(FALSE), so should I do a GetWindowText in this event and see if its empty?

          void CDlgMineName::OnChangeEditminename()
          {
          CString abc;
          m_myEdit.GetWindowText(abc);
          if(abc=="")
          {
          m_buttonminename.EnableWindow(FALSE);
          }
          else
          {
          m_buttonminename.EnableWindow(TRUE);
          }

          }

          What do you think about this? Too contrived? Thanks, ns:)

          T 1 Reply Last reply
          0
          • R Roger Allen

            For the EN_CHANGE you would just write

            CString name ;
            m_editMineName.GetWindowText(name) ;
            GetDlgItem(IDC_BUTTON_DONE)->EnableWindow(name.GetLength() > 0) ;

            Roger Allen Sonork 100.10016 I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.

            N Offline
            N Offline
            ns
            wrote on last edited by
            #5

            Thanks! I was going about doing that but I really like your succintness and style! Thanks, ns

            1 Reply Last reply
            0
            • N ns

              It probably is, but heres what I do in the function:

              void CDlgMineName::OnChangeEditminename()
              {

              m\_buttonminename.EnableWindow(TRUE);
              

              }

              If the change was of a "negative type" i.e. nothings left in the CEdit, I want to EnableWindow(FALSE), so should I do a GetWindowText in this event and see if its empty?

              void CDlgMineName::OnChangeEditminename()
              {
              CString abc;
              m_myEdit.GetWindowText(abc);
              if(abc=="")
              {
              m_buttonminename.EnableWindow(FALSE);
              }
              else
              {
              m_buttonminename.EnableWindow(TRUE);
              }

              }

              What do you think about this? Too contrived? Thanks, ns:)

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              One line does it all:

              m_button.EnableWindow(m_edit.GetWindowTextLength() > 0);

              Tomasz Sowinski -- http://www.shooltz.com

              Free your mind and your ass will follow.

              1 Reply Last reply
              0
              • N ns

                A dilemma: I want a "done" button to be disabled until the user adds omething to the CEdit. Fine. I trapped the EN_CHANGE, and the button comes alive as soon as the user enters anything. Problem is, I dont ever want this field to be empty, and if after typing a letter in, the user goes back and deletes it, my "done" button is still enabled. It should only be enabled when theres something in the CEdit. How do I do this? ====================================================================================== My other tactic was to test when the "done' was pressed like this(below) but it freezes my program and doesnt give me a chance to enter something into the CEdit:

                void CDlgMineName::OnButtonDone()
                {

                CString UserEntry;
                
                m\_editMineName.GetWindowText(UserEntry);
                
                while (UserEntry =="")
                {
                	m\_editMineName.SetFocus();
                
                	m\_editMineName.GetWindowText(UserEntry);`why cant I enter anything here?` 
                }
                
                It freezes  and I have to kill it from task manager. Is it obvious why ?
                

                Thanks, ns

                S Offline
                S Offline
                Sayan Mukherjee
                wrote on last edited by
                #7

                Hi, Please find below a possible way to do it using MFC. It is in your lines of thought and EN_CHANGE does it. When the application starts the button will be disabled. As you type in the edit box or delete text EN_CHANGE fires. Keep on measuring the length of the string. Code follows: Class declaration: class CEditControlDlg : public CDialog { // Construction public: CEdit *m_pEdit; **// Added by Sayan** CButton *m_pButton; **// Added by Sayan** CEditControlDlg(CWnd* pParent = NULL); // standard constructor // ... // ... } Function definition - InitDialog(): BOOL CEditControlDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_pEdit = (CEdit *)GetDlgItem(EF_TEXT); **// Added by Sayan** m_pButton = (CButton *)GetDlgItem(PB_DONE); **// Added by Sayan** m_pButton->EnableWindow(FALSE); // Added by Sayan return TRUE; // return TRUE unless you set the focus to a control } Function definition - EN_CHANGE handler function: void CEditControlDlg::OnChangeText() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here CString strText; m_pEdit->GetWindowText(strText); if (!strText.GetLength()) { m_pButton->EnableWindow(FALSE); } else { m_pButton->EnableWindow(); } } With best regards, Sayan Email:sayanmukherjee@indiatimes.com

                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