Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFC edit control strange behaviour

Tags:

mfc

I ran into an awkward behaviour of CEdit when setting it's font: for a certain font size, letters like 'g' or 'j' have the bottom part missing, regardless of CEdit's rect height. 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 fine enter image description here

As you can observe, the CEdit's rect height is larger than the text's height in both cases. The parent control is a CDialog; the font is set on ::OnInitDialog and CEdit's size is set with SetWindowPos method on ::OnShowWindow. What could cause this, and how should i handle it?

Edit: i've tried @rrirower 's suggestion, and now i'm confussed; adding the CEdit's CDC to CFont's initialization changed the text's mask alot (you may not see it from the beggining, but i have other edit's with the old font on the same page and there's a big difference):

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

enter image description here

like image 260
MRM Avatar asked Nov 10 '22 12:11

MRM


1 Answers

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
like image 90
Suneesh Avatar answered Nov 24 '22 00:11

Suneesh