dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Count number of physical lines in the text control

  1. #1
    Join Date
    Aug 2002
    Posts
    712

    Count number of physical lines in the text control

    Hi, ALL,
    In the text control there are 2 types of line: physical and logical.

    Physical lines are divided by "\n\r" characters ("\n" on *nix), logical lines are used when the control is narrower than the text typed and there is a so-called soft "\n\r" character inserted by the control in order for not to display the horizontal scrollbar.

    It looks like EM_GETLINECOUNT will return the number of logical lines, according to this. Is there anything that will return me a number of physical lines? Or I will have to manually go through the text buffer and count number of "\n\r" characters?

    Thank you.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,178

    Re: Count number of physical lines in the text control

    Does MFC offer any methods that help? Even if you aren't using MFC you can look at its source code for implementation.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: Count number of physical lines in the text control

    Quote Originally Posted by OneEyeMan View Post
    ...
    It looks like EM_GETLINECOUNT will return the number of logical lines, according to this. Is there anything that will return me a number of physical lines? Or I will have to manually go through the text buffer and count number of "\n\r" characters?
    1. Are you using a multi-line edit control?
    2. How did you check that EM_GETLINECOUNT will return the number of logical lines?
    Victor Nijegorodov

  4. #4
    Join Date
    Aug 2002
    Posts
    712

    Re: Count number of physical lines in the text control

    Hi, VictorN,
    Sorry for the late reply...
    Quote Originally Posted by VictorN View Post
    1. Are you using a multi-line edit control?
    Yes. It doesn't make sense otherwise.

    Quote Originally Posted by VictorN View Post
    2. How did you check that EM_GETLINECOUNT will return the number of logical lines?
    MSDN says so. And I tested.
    It counts number of wrapped lines ("logical"), not the physical ones.

    Thank you.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: Count number of physical lines in the text control

    Quote Originally Posted by OneEyeMan View Post
    MSDN says so. And I tested.
    It counts number of wrapped lines ("logical"), not the physical ones.
    Well, i can understand (or just guess) why. To have a way to exactly know/calculate the position (in the control) of any character in the text depending on the "word wrap" option.

    Why do you need to know the number of "physical lines"?
    Victor Nijegorodov

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: Count number of physical lines in the text control

    Why not just get the text and count the new lines?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)