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. Problem with retrieveing number of characters in a multiline edit control

Problem with retrieveing number of characters in a multiline edit control

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 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.
  • G Offline
    G Offline
    gabbana
    wrote on last edited by
    #1

    Hi, I have some problems with the edit control. I want to count the chars if it, but the message i send to the control only receives the right character num for the first line. For exmaple. The first line can have 60 chars. If I only enter 50 or so, the message gives me the right count. If I then enter a longer text, so that the first line have all the 60 chars and the second line have only 30 chars, then the message returns also a number of 60 chars for the second line, but why ? Where is the problem ? My line:

    dwChars = (DWORD)SendDlgItemMessage(hwnd,IDC_INPUT,EM_LINELENGTH,(WPARAM)3,(LPARAM)0);

    I hardcoded the line 3 here, normally I am going through a for loop.

    G CPalliniC 2 Replies Last reply
    0
    • G gabbana

      Hi, I have some problems with the edit control. I want to count the chars if it, but the message i send to the control only receives the right character num for the first line. For exmaple. The first line can have 60 chars. If I only enter 50 or so, the message gives me the right count. If I then enter a longer text, so that the first line have all the 60 chars and the second line have only 30 chars, then the message returns also a number of 60 chars for the second line, but why ? Where is the problem ? My line:

      dwChars = (DWORD)SendDlgItemMessage(hwnd,IDC_INPUT,EM_LINELENGTH,(WPARAM)3,(LPARAM)0);

      I hardcoded the line 3 here, normally I am going through a for loop.

      G Offline
      G Offline
      gabbana
      wrote on last edited by
      #2

      Okay i found the error. I think the wparam needs the offset of the char in the complete edit field. So I first sent the EM_LINEINDEX message and now I thinks its working.

      1 Reply Last reply
      0
      • G gabbana

        Hi, I have some problems with the edit control. I want to count the chars if it, but the message i send to the control only receives the right character num for the first line. For exmaple. The first line can have 60 chars. If I only enter 50 or so, the message gives me the right count. If I then enter a longer text, so that the first line have all the 60 chars and the second line have only 30 chars, then the message returns also a number of 60 chars for the second line, but why ? Where is the problem ? My line:

        dwChars = (DWORD)SendDlgItemMessage(hwnd,IDC_INPUT,EM_LINELENGTH,(WPARAM)3,(LPARAM)0);

        I hardcoded the line 3 here, normally I am going through a for loop.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        EM_LINELENGTH message wants the index of a character (of the wanted line) as WPARAM, hence, if you need the lenght of the third line, use:

        INT iCharIndex = SendDlgItemMessage(hwnd,IDC_INPUT,EM_LINEINDEX,(WPARAM)2,(LPARAM)0);
        INT iLineLen = SendDlgItemMessage(hwnd,IDC_INPUT,EM_LINELENGTH,(WPARAM)iCharIndex,(LPARAM)0);

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        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