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. GetTextExtent

GetTextExtent

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

    Hi. I'm trying to get the pixel length of a string inside a CStatic, so I can chop it off in the middle and put "..." in the middle. The string happens to be a filename. So if C:/WINNT/ABC/XXX/YYY/ZZZ/DEF/COMMAND.COM is too long to fit inside CStatic width, it will be something like C:/WINNT/AB...EF/COMMAND.COM that will fit. I'm using true type font for the CStatic, so I have to calculate this on the fly. The problem is I have to get the DC to do GetTextExtent, and I dont want to override OnPaint method. I was hoping to get this before the OnPaint is called (actually I dont mind looping on SetWindowText until the length fits) Any ideas? Thanks

    M 1 Reply Last reply
    0
    • C crewchill

      Hi. I'm trying to get the pixel length of a string inside a CStatic, so I can chop it off in the middle and put "..." in the middle. The string happens to be a filename. So if C:/WINNT/ABC/XXX/YYY/ZZZ/DEF/COMMAND.COM is too long to fit inside CStatic width, it will be something like C:/WINNT/AB...EF/COMMAND.COM that will fit. I'm using true type font for the CStatic, so I have to calculate this on the fly. The problem is I have to get the DC to do GetTextExtent, and I dont want to override OnPaint method. I was hoping to get this before the OnPaint is called (actually I dont mind looping on SetWindowText until the length fits) Any ideas? Thanks

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      PathSetDlgItemPath() will do all that for you :) --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

      B 1 Reply Last reply
      0
      • M Michael Dunn

        PathSetDlgItemPath() will do all that for you :) --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

        B Offline
        B Offline
        basementman
        wrote on last edited by
        #3

        Or, if you really want to calculate it yourself, simply get the dc when you need to compute the size manually like this: ... CWnd *pStatic = GetDlgItem(IDC_MY_STATIC_FILENAME); CDC *pDC = pStatic->GetDC(); pDC->GetTextExtent() or pDC->DrawText(cText,&oRect,DT_CALCRECT.... your calculations... pStatic->ReleaseDC(pDC);

        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