-
June 3rd, 2013, 02:54 AM
#1
GetTextExtent don't detect the font size
Hi,
I need use GetTextExtent and I don't understant why GetTextExtent always return the same value if I change some values of the selected font. This is my example:
Code:
LOGFONT lf;
pOldFont->GetLogFont(&lf);
CString sExampleSizeByChar;
sExampleSizeByChar = _T("hello");
DWORD dwPixelsByChar = dc.GetTextExtent(sExampleSizeByChar).cx / 1.15;
// I change the font size
lf.lfHeight = lf.lfHeight + 10;
lf.lfWidth = lf.lfWidth + 10;
CFont* pFont = new CFont;
pFont->CreateFontIndirect(&lf);
dc.SelectObject(pFont);
dwPixelsByChar = dc.GetTextExtent(sExampleSizeByChar).cx / 1.15;
Why I get always the value 24 when I call GetTextExtent if I change the font size?
Thank you very much.
-
June 3rd, 2013, 03:27 AM
#2
Re: GetTextExtent don't detect the font size
What is the dc?
Did you select the proper font in it before your first call of
Code:
DWORD dwPixelsByChar = dc.GetTextExtent(sExampleSizeByChar).cx / 1.15;
What does the CreateFontIndirect(&lf) return? TRUE or FALSE?
Victor Nijegorodov
-
June 3rd, 2013, 04:31 AM
#3
Re: GetTextExtent don't detect the font size
LOGFONT
You need to see how many points it makes when you add 10 pixels to font height. I doubt the system feels any difference while mapping to an existent font.
Best regards,
Igor
-
June 21st, 2013, 03:22 AM
#4
Re: GetTextExtent don't detect the font size
Originally Posted by Igor Vartanov
LOGFONT
You need to see how many points it makes when you add 10 pixels to font height. I doubt the system feels any difference while mapping to an existent font.
Yes, you are right, the code was working correctly. I have changed 10 to 50 and I can see the difference in the return value of function GetTextExtent.
Thank you very much for your replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|