-
July 25th, 2021, 07:37 PM
#1
Why Creatfont not working?
Hi,
I'm using the font Calibri,
I need to calculated fontwidth of CString L"testtextwidth" from the fontsize 14.5 and 16
I used the Createfont function as follows:
Code:
//initialize
HDC hDC = ::GetDC(NULL);
CFont hFont;
double height=14.5;
//creat font
hFont.CreateFontW(height, 0, 0, 0,
bold == 1 ? FW_BOLD : FW_NORMAL,FALSE, FALSE, FALSE, ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE, L"Calibri");
//get font size
SelectObject(hDC, hFont);
SIZE size = { 0 };
GetTextExtentPoint32(hDC, L"testtextwidth", _tcslen(L"testtextwidth"), &size);
and the same with height=16.
however both of these sizes (size.y) give the same width.
where did i go wrong?
2 diferrent font size but same width?
Thanks you!
Last edited by Dang.D.Khanh; July 28th, 2021 at 11:49 AM.
-
July 26th, 2021, 02:45 AM
#2
Re: Why Creatfont not working?
Please, edit your post adding proper code indentations! Otherwise it is absolutely non-readable.
Victor Nijegorodov
-
July 26th, 2021, 08:04 AM
#3
Re: Why Creatfont not working?
Originally Posted by VictorN
Please, edit your post adding proper code indentations! Otherwise it is absolutely non-readable.
Hi Sir,
I want to calculate the width of a string, the above code is what I have from this post.
From h=11point I switch to 14.5pixel and calculate the width like the code, the problem is h=12point has the same width as well.
What should I do to fix it?
-
July 26th, 2021, 11:07 AM
#4
Re: Why Creatfont not working?
Originally Posted by Dang.D.Khanh
... the above code is what I have from this post.
Sorry, but I could not find in this post anything similar to what you have posted as a "code".
Victor Nijegorodov
-
July 26th, 2021, 11:46 AM
#5
Re: Why Creatfont not working?
Originally Posted by VictorN
Sorry, but I could not find in this post anything similar to what you have posted as a "code".
Hi Sir,
You can see I'm getting ideas from that post.
The usage function are all there.
Code:
CreateFont
GetTextExtentPoint32
DrawText
I have used CFont instead of HFONT because result has not changed.
Tags for this Thread
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
|