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!
Re: Why Creatfont not working?
Please, edit your post adding proper code indentations! Otherwise it is absolutely non-readable. :sick:
Re: Why Creatfont not working?
Quote:
Originally Posted by
VictorN
Please, edit your post adding proper code indentations! Otherwise it is absolutely non-readable. :sick:
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?
Re: Why Creatfont not working?
Quote:
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". :rolleyes:
Re: Why Creatfont not working?
Quote:
Originally Posted by
VictorN
Sorry, but I could not find in this
post anything similar to what you have posted as a "code". :rolleyes:
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.