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. a question about Edit Box

a question about Edit Box

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • S Offline
    S Offline
    Shuang Wu
    wrote on last edited by
    #1

    I added an Edit Box to my Dialog. i'd like it only accept numeric input. when a non-numeric key is pressed a warning dialog will apear. i mean, just after press the key, not after my button 'Subject' is pressed, the dialog appears. Hello World

    M 1 Reply Last reply
    0
    • S Shuang Wu

      I added an Edit Box to my Dialog. i'd like it only accept numeric input. when a non-numeric key is pressed a warning dialog will apear. i mean, just after press the key, not after my button 'Subject' is pressed, the dialog appears. Hello World

      M Offline
      M Offline
      monrobot13
      wrote on last edited by
      #2

      If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron

      S 2 Replies Last reply
      0
      • M monrobot13

        If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron

        S Offline
        S Offline
        Shuang Wu
        wrote on last edited by
        #3

        Yes, your suggestion sounds much better; and Thanks very much. Hello World

        1 Reply Last reply
        0
        • M monrobot13

          If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron

          S Offline
          S Offline
          Shuang Wu
          wrote on last edited by
          #4

          monrobot13 wrote: **Shuang. Wu wrote: **when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.**** BTW, i failed to do as my previous idea. I would like to know if there is some way to do it? Hello World

          M 1 Reply Last reply
          0
          • S Shuang Wu

            monrobot13 wrote: **Shuang. Wu wrote: **when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.**** BTW, i failed to do as my previous idea. I would like to know if there is some way to do it? Hello World

            M Offline
            M Offline
            Mahendra_786
            wrote on last edited by
            #5

            You can do this using CWnd::SubclassDlgItem Derive your own class say CMyEdit from CEdit and add a WM_CHAR handler: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar >= '0' && nChar <= '9') { CEdit::OnChar(nChar, nRepCnt, nFlags); return; } else { AfxMessageBox("Invalid Key"); } } In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); where m_myEdit is a Dialog member of type CMyEdit and IDC_EDIT1 is the edit control id. Hope this helps!

            D 1 Reply Last reply
            0
            • M Mahendra_786

              You can do this using CWnd::SubclassDlgItem Derive your own class say CMyEdit from CEdit and add a WM_CHAR handler: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar >= '0' && nChar <= '9') { CEdit::OnChar(nChar, nRepCnt, nFlags); return; } else { AfxMessageBox("Invalid Key"); } } In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); where m_myEdit is a Dialog member of type CMyEdit and IDC_EDIT1 is the edit control id. Hope this helps!

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

              Mahendra_786 wrote: In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).


              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

              M 1 Reply Last reply
              0
              • D David Crow

                Mahendra_786 wrote: In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                M Offline
                M Offline
                Mahendra_786
                wrote on last edited by
                #7

                That is :rolleyes:HIGHLY:rolleyes: correct and my way in fact may be insufficient not just unnecessary. In fact DDX_* somewhere calls SubclassWindow to do this. Moreover the way I suggested I am not sure how UpdateData will work beside other side-effects. Due Regards Mahendra

                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