MFC edits strange behavior

I came across the inconvenient behavior of CEdit when adjusting its font: for a certain font size, letters like "g" or "j" have the missing part, regardless of the height of the CEdit rectangle. Here are two examples:

CFont *ctrlFont = new CFont(); ctrlFont ->CreatePointFont(80, "Arial Black"); CEdit m_editName; m_editName.SetFont(ctrlFont); 

with this result: enter image description here

but for

 ctrlFont ->CreatePointFont(100, "Arial Black"); 

everything is good enter image description here

As you can see, the height of the CEdit rectangle is greater than the height of the text in both cases. The parent control is CDialog; the font is set to ::OnInitDialog , and the size of CEdit is set using the SetWindowPos method to ::OnShowWindow . What can cause this, and how should I deal with it?

Edit: I tried the @rrirower sentence, and now I'm being fooled; adding CEdit CDC initialization to CFont greatly changed the text mask (you may not see it from the very beginning, but I have another edit with the old font on the same page and there is a big difference):

 ctrlFont1->CreatePointFont(80, "Arial Black", m_editName.GetDC()); 

enter image description here

+5
source share
1 answer

Call CreateFont () with all parameters

  font.CreateFont( 12, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial"))); // lpszFacename 
0
source

All Articles