CFontDialog and LOGFONT :: MFC
I have a question about the use of LOGFONT with CFontDialog. I would like to have an option to change the font including size, weight, etc. I implemented a feature with CFontDialog support. I pass a pointer to a LOGFONT object when I instantiate the CFontDialog. Upon DoModal() == IDOK, I create a new LOGFONT object and assign it the value from CFontDialog. The program works sometimes. I am experiencing some weird reactions. First, the size of the font rarely comes out correctly. The size seems to be 10x *smaller* than the actual size of whatever the user selects from CFontDialog. Vice versa, when CFontDialog first starts up, I am able to pass it a LOGFONT of the current font. Again, it reads and interprets the font size incorrectly. For example, all default font size is 110 (11 points). However, when CFontDialog starts up, it interprets 110 as 83.
Here is a concise example.
LOGFONT *mLFont = new LOGFONT;
memset(mLFont, 0, sizeof(LOGFONT);
mLFont->lfHeight = 110;
strcpy(mLFont->lfFaceName, "Microsoft Sans Serif");
CFont *myFont = new CFont;
// Everything is good up to this point.
if (myFDlg.DoModal() == IDOK)
// I am not sure if I need to create a new (clean) LOGFONT object
if (mLFont != NULL)
mLFont = NULL;
mLFont = new LOGFONT;
memset(mLFont, 0, sizeof(LOGFONT));
Okay. For some reason, the actual font that GetCurrentFont(...) passes back is 10x smaller than the actual size or the size that the user actually thought it want it to be
I am using CEditView. I use GetEditCtrl().SetFont() to set the font. I use GetEditCtrl().SetWindowText(...) to set the text.
I mentioned about deleting a LOGFONT object and allocating a new object each time I make a change to an LOGFONT object. Is that necessary?
Okay. The solution is to use CreateFontIndirect() instead of CreatePointFontIndirect(). I have no idea why that is.
Also, when I first instantiate a CFontDialog and pass in a reference of a LOGFONT object of the current font, for some reason CFontDialog does not recognize its height. It only recognizes the height after the user makes changes via CFontDialog.