CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2013
    Posts
    3

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  4. #4
    Join Date
    Jun 2013
    Posts
    3

    Re: GetTextExtent don't detect the font size

    Quote Originally Posted by Igor Vartanov View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured