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

A question

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 5 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.
  • P Offline
    P Offline
    pantao551
    wrote on last edited by
    #1

    How can I make a message when the number of charactors in the editbox reaches 3? Thanks!

    O PJ ArendsP L 3 Replies Last reply
    0
    • P pantao551

      How can I make a message when the number of charactors in the editbox reaches 3? Thanks!

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      Handle the EN_CHANGE message sent by the editbox to it's parent window. Send a WM_GETTEXTLENGTH message to the editbox to check how many characters are in it.


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      O P 2 Replies Last reply
      0
      • P pantao551

        How can I make a message when the number of charactors in the editbox reaches 3? Thanks!

        O Offline
        O Offline
        Owner drawn
        wrote on last edited by
        #3

        I think you want to display a message box right? So you can use EN_CHANGE handler for this purpose. And use GetWindowText(...) to count the number of chars in the edit. But this won't prevent the user from furthur inserting any chars in the edit. But you can prevent this by subclassing the edit and handling WM_CHAR message. If the count in less than 3 then fine call the base class handler or else don't call it instead display a message box. This will prevent the user from inserting further chars. Hope this is what you want.

        Love Forgives--Love Gives--Jesus is Love :)

        --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

        PJ ArendsP P 2 Replies Last reply
        0
        • PJ ArendsP PJ Arends

          Handle the EN_CHANGE message sent by the editbox to it's parent window. Send a WM_GETTEXTLENGTH message to the editbox to check how many characters are in it.


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

          O Offline
          O Offline
          Owner drawn
          wrote on last edited by
          #4

          PJ Arends wrote:

          WM_GETTEXTLENGTH

          :cool:

          PJ Arends wrote:

          A question and An answer

          He he funny.

          Love Forgives--Love Gives--Jesus is Love :)

          --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

          P 1 Reply Last reply
          0
          • P pantao551

            How can I make a message when the number of charactors in the editbox reaches 3? Thanks!

            L Offline
            L Offline
            lastgen
            wrote on last edited by
            #5

            I'll assume you are using MFC, so if so you just need to write a function on the edit boxes EN_CHANGE event. The code insode the function would be something like this { // m_EditText is the CString that stores the edit text(whatever you called it) if (strlen(m_EditText) > 3) { // Use other message box function and add correct handle if you know it MessageBox(NULL, "My Text is to long", "Message Caption", 0); } } I believe there are functions to get the size directly from the edit box in MFC but I don't like MFC so I tend to avoid it where possible. -- modified at 23:05 Wednesday 4th January, 2006

            1 Reply Last reply
            0
            • O Owner drawn

              PJ Arends wrote:

              WM_GETTEXTLENGTH

              :cool:

              PJ Arends wrote:

              A question and An answer

              He he funny.

              Love Forgives--Love Gives--Jesus is Love :)

              --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

              P Offline
              P Offline
              Prakash Nadar
              wrote on last edited by
              #6

              Owner drawn wrote:

              An answer TO an Answer

              Thats funny too.


              -Prakash

              1 Reply Last reply
              0
              • O Owner drawn

                I think you want to display a message box right? So you can use EN_CHANGE handler for this purpose. And use GetWindowText(...) to count the number of chars in the edit. But this won't prevent the user from furthur inserting any chars in the edit. But you can prevent this by subclassing the edit and handling WM_CHAR message. If the count in less than 3 then fine call the base class handler or else don't call it instead display a message box. This will prevent the user from inserting further chars. Hope this is what you want.

                Love Forgives--Love Gives--Jesus is Love :)

                --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #7

                Owner drawn wrote:

                But this won't prevent the user from furthur inserting any chars in the edit. But you can prevent this by subclassing the edit and handling WM_CHAR message. If the count in less than 3 then fine call the base class handler or else don't call it instead display a message box. This will prevent the user from inserting further chars.

                EM_LIMITTEXT


                "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                Within you lies the power for good; Use it!

                O 1 Reply Last reply
                0
                • PJ ArendsP PJ Arends

                  Owner drawn wrote:

                  But this won't prevent the user from furthur inserting any chars in the edit. But you can prevent this by subclassing the edit and handling WM_CHAR message. If the count in less than 3 then fine call the base class handler or else don't call it instead display a message box. This will prevent the user from inserting further chars.

                  EM_LIMITTEXT


                  "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                  O Offline
                  O Offline
                  Owner drawn
                  wrote on last edited by
                  #8

                  PJ Arends wrote:

                  EM_LIMITTEXT

                  :cool:

                  Love Forgives--Love Gives--Jesus is Love :)

                  --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

                  1 Reply Last reply
                  0
                  • PJ ArendsP PJ Arends

                    Handle the EN_CHANGE message sent by the editbox to it's parent window. Send a WM_GETTEXTLENGTH message to the editbox to check how many characters are in it.


                    "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                    P Offline
                    P Offline
                    pantao551
                    wrote on last edited by
                    #9

                    Thanks a lot!

                    1 Reply Last reply
                    0
                    • O Owner drawn

                      I think you want to display a message box right? So you can use EN_CHANGE handler for this purpose. And use GetWindowText(...) to count the number of chars in the edit. But this won't prevent the user from furthur inserting any chars in the edit. But you can prevent this by subclassing the edit and handling WM_CHAR message. If the count in less than 3 then fine call the base class handler or else don't call it instead display a message box. This will prevent the user from inserting further chars. Hope this is what you want.

                      Love Forgives--Love Gives--Jesus is Love :)

                      --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

                      P Offline
                      P Offline
                      pantao551
                      wrote on last edited by
                      #10

                      What I wanted was moving the focus of my keyboard to another place as soon as the number of charactors in the editbox reaches 3. And I think what you told me can solve my problem. Thanks a lot!

                      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