Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, everyone!
I am wondering that: are there any differences between nHeight field in CreateFont method of CFont class and lfHeight field of LOGFONT structure? Because when I create a font by 2 ways:
1,
C++
//other codes
CFont myFont;
myFont.CreateFont(m_iSize, 0, 0, 0, 400, m_bItalic, m_bUnder, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_SWISS, m_strFont);
//other codes

2,
C++
//other codes
CFontDialog fontDlg;
int iOption = fontDlg.DoModal();
if (iOption!=IDOK)
{
	return;
}
LOGFONT logFont;
fontDlg.GetCurrentFont(&logFont);
CFont myFont;
myFont.CreateFontIndirect(&logFont);
//other codes

HERE: certainly I must pass m_iSize, m_bItalic, bUnder, m_strFont equals to the selection in FontDialog. But 2 fonts I received are different, at least is its size.
Please explain for me!

Thanks so much!
Posted
Updated 26-Sep-10 7:11am
v2

1 solution

From the MSDN page for CFont.CreateFontIndirect()


This font has the characteristics specified in the LOGFONT structure. When the font is selected by using the CDC::SelectObject member function, the GDI's font mapper attempts to match the logical font with an existing physical font. If it fails to find an exact match for the logical font, it provides an alternative whose characteristics match as many of the requested characteristics as possible.


I have bolded the relevant bit.

Is there a possibility that this is happening in your case?

I should say that I have not used C, C++ or MFC for years and years so any follow-up questions would be a waste of your time. :)

I just remembered this, for some odd reason.

Good luck! :)
 
Share this answer
 
Comments
duong2179 27-Sep-10 10:55am    
thanks Henry Minute. I will find again this problem in MSDN.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900