GetTextExtent
-
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
-
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
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 -
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 meOr, 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);