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. Character Counter in MFC

Character Counter in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++javatoolshelpquestion
5 Posts 2 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.
  • T Offline
    T Offline
    tlerner
    wrote on last edited by
    #1

    If anyone can help me with a character counter, I would be very appreciative. I have a Rich Text Edit box in an MFC app. I would like to limit the number of characters a user enters by having a "Characters Left" count box below my edit box indicating how many additional characters the user has left. This counter chould be dynamic enough so users would actually see the number decrement by one for each character typed, and if they deleted a 5 letter word, it should go up by 5. In addition, when the counter is 0, the edit box should not allow any more input. This should be similar to the java script done on many HTMLs. Anyone ever done this before in C++ MFC? Can anyone provide me with a suggestion on where to begin? Thank you!!!

    W 1 Reply Last reply
    0
    • T tlerner

      If anyone can help me with a character counter, I would be very appreciative. I have a Rich Text Edit box in an MFC app. I would like to limit the number of characters a user enters by having a "Characters Left" count box below my edit box indicating how many additional characters the user has left. This counter chould be dynamic enough so users would actually see the number decrement by one for each character typed, and if they deleted a 5 letter word, it should go up by 5. In addition, when the counter is 0, the edit box should not allow any more input. This should be similar to the java script done on many HTMLs. Anyone ever done this before in C++ MFC? Can anyone provide me with a suggestion on where to begin? Thank you!!!

      W Offline
      W Offline
      wb
      wrote on last edited by
      #2

      Hi! the "normal" edit control has a method, that allows you to set the maximum input len. So I guess, the RichEditControl has some similar method. and then, you can catch the TEXT_CHANGED message (don't know the correct name :) ) , get the text from the control, calculate the Len and update your "counter" control.

      T 1 Reply Last reply
      0
      • W wb

        Hi! the "normal" edit control has a method, that allows you to set the maximum input len. So I guess, the RichEditControl has some similar method. and then, you can catch the TEXT_CHANGED message (don't know the correct name :) ) , get the text from the control, calculate the Len and update your "counter" control.

        T Offline
        T Offline
        tlerner
        wrote on last edited by
        #3

        Yea, I know the "concept" behind what I need to do, I just cant find any specifics. TEXT_CHANGED is nice, but again, the real name alludes me. I simply cannot find it and I am getting a little frustrated. :((

        W 1 Reply Last reply
        0
        • T tlerner

          Yea, I know the "concept" behind what I need to do, I just cant find any specifics. TEXT_CHANGED is nice, but again, the real name alludes me. I simply cannot find it and I am getting a little frustrated. :((

          W Offline
          W Offline
          wb
          wrote on last edited by
          #4

          :) It seems, you must derive a class from CRichEditCtrl and catch the WM_KEYUP message. Don't know why, but my parent window don't get any messages from the RichEdit :(

          T 1 Reply Last reply
          0
          • W wb

            :) It seems, you must derive a class from CRichEditCtrl and catch the WM_KEYUP message. Don't know why, but my parent window don't get any messages from the RichEdit :(

            T Offline
            T Offline
            tlerner
            wrote on last edited by
            #5

            Yea, it seems that the parent window doesn't get the KEYUP message with me either and that was the problem I was having. I solved this problem by adding a message handler to the IDC_EDIT for EN_CHANGE messages. That worked great. I dont understand how or why it works with a rich edit, but who knows...and at this point who cares. Its done! Thanks for the help.

            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