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. Split paragraph into lines based on width in pixels

Split paragraph into lines based on width in pixels

Scheduled Pinned Locked Moved C / C++ / MFC
cssjsonhelpquestion
8 Posts 5 Posters 2 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
    Steve Thresher
    wrote on last edited by
    #1

    I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?

    D L J 3 Replies Last reply
    0
    • S Steve Thresher

      I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Depends on the context. What are you doing exactly? If you're drawing the string yourself, the Graphics method DrawString already does this for you. You just have to provide the rectangle to fit the string in.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Depends on the context. What are you doing exactly? If you're drawing the string yourself, the Graphics method DrawString already does this for you. You just have to provide the rectangle to fit the string in.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        S Offline
        S Offline
        Steve Thresher
        wrote on last edited by
        #3

        Thanks for the suggestion but I'm looking to determine the starting offset of each line within the paragraph. I could manually parse the string and use GetTextExtentPoint32() to work it out myself but I imagine that will be slow and I thought maybe an API might already exist as something like an edit control will already be doing something similar.

        AxisFirst For Business

        D 1 Reply Last reply
        0
        • S Steve Thresher

          Thanks for the suggestion but I'm looking to determine the starting offset of each line within the paragraph. I could manually parse the string and use GetTextExtentPoint32() to work it out myself but I imagine that will be slow and I thought maybe an API might already exist as something like an edit control will already be doing something similar.

          AxisFirst For Business

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Ah, OK. I think you're looking for Graphics.MeasureCharacterRanges[^].

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          1 Reply Last reply
          0
          • S Steve Thresher

            I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Probably easier to use an Edit Control | Microsoft Docs[^].

            L 1 Reply Last reply
            0
            • L Lost User

              Probably easier to use an Edit Control | Microsoft Docs[^].

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              +100 to that answer .. Multiline edit boxes already exist why re-invent the wheel.

              In vino veritas

              L 1 Reply Last reply
              0
              • L leon de boer

                +100 to that answer .. Multiline edit boxes already exist why re-invent the wheel.

                In vino veritas

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Thanks, I totally agree.

                1 Reply Last reply
                0
                • S Steve Thresher

                  I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?

                  J Offline
                  J Offline
                  Joe Woodbury
                  wrote on last edited by
                  #8

                  Look at ExtTextOut.

                  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