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. How to measure a Char width in a text

How to measure a Char width in a text

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
10 Posts 6 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.
  • S Offline
    S Offline
    susanne1
    wrote on last edited by
    #1

    i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

    _ R CPalliniC C A 5 Replies Last reply
    0
    • S susanne1

      i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Let me google that for you![^] and remember that google or any search engine is your friend.

      You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

      1 Reply Last reply
      0
      • S susanne1

        i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        What does it have to do with finding the character width? Can't you just call GetCursorPos()[^]?

        It is a crappy thing, but it's life -^ Carlo Pallini

        S 1 Reply Last reply
        0
        • R Rajesh R Subramanian

          What does it have to do with finding the character width? Can't you just call GetCursorPos()[^]?

          It is a crappy thing, but it's life -^ Carlo Pallini

          S Offline
          S Offline
          susanne1
          wrote on last edited by
          #4

          no because i need to find th x and y where the mouse clicked in order to mark the text to copy it.

          R 1 Reply Last reply
          0
          • S susanne1

            i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

            CPalliniC Online
            CPalliniC Online
            CPallini
            wrote on last edited by
            #5

            CDC::GetTextExtent [^]. :)

            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?

            S 1 Reply Last reply
            0
            • CPalliniC CPallini

              CDC::GetTextExtent [^]. :)

              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]

              S Offline
              S Offline
              susanne1
              wrote on last edited by
              #6

              This method gives me the width of the whole text, wht i exactly need, is the width in pixel for each charchter in the text.

              CPalliniC 1 Reply Last reply
              0
              • S susanne1

                no because i need to find th x and y where the mouse clicked in order to mark the text to copy it.

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                susanne1 wrote:

                i need to find th x and y where the mouse clicked in order to mark the text to copy it.

                Ugh... You need to find x and y? Ya know? That's *exactly* what GetCursorPos() does. :rolleyes:

                It is a crappy thing, but it's life -^ Carlo Pallini

                1 Reply Last reply
                0
                • S susanne1

                  i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #8

                  What are you trying to achieve exactly ? On what the user is supposed to click and what do you want to do in response ?

                  Cédric Moonen Software developer
                  Charting control [v2.0] OpenGL game tutorial in C++

                  1 Reply Last reply
                  0
                  • S susanne1

                    i need to measure a char width in a text , to detrmine where the user clicked. void CTest_View::OnLButtonDown(UINT nFlags, CPoint point) { CString strInput; strInput = "Text 1234"; int nX = point.x; // but this is the position in pixel. } please help. Thanks

                    A Offline
                    A Offline
                    Adam Roderick J
                    wrote on last edited by
                    #9

                    To get the character width you can use below sequence. Firstly use GetCursorPos() to get the cursor point and use HWND WindowFromPoint( POINT Point ) To get the handle and from that handle use the below API in which the LPTEXTMETRIC haves the character width. BOOL GetTextMetrics( HDC hdc, // handle to DC LPTEXTMETRIC lptm // text metrics ); i cannot understand whats your need to do such a step, well hope you are looking for the above :)

                    modified on Monday, July 13, 2009 4:46 AM

                    1 Reply Last reply
                    0
                    • S susanne1

                      This method gives me the width of the whole text, wht i exactly need, is the width in pixel for each charchter in the text.

                      CPalliniC Online
                      CPalliniC Online
                      CPallini
                      wrote on last edited by
                      #10

                      Actually this method gives the width of the passed string, if you pass a single-character string then you get the width of such character. :)

                      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