GetTextExtent don't detect the font size
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: GetTextExtent don't detect the font size

  1. #1
    Join Date
    Jun 2013
    Posts
    2

    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
    Wallisellen (ZH), Switzerland
    Posts
    17,266

    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
    5,923

    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
    2

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center