CFontDialog and LOGFONT :: MFC

This is a discussion on CFontDialog and LOGFONT :: MFC within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I have a question about the use of LOGFONT with CFontDialog. I would like to have an option to ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    CFontDialog and LOGFONT :: MFC

    Hi.

    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;
    myFont->CreatePointFontIndirect(mLFont);

    // Everything is good up to this point.

    CFontDialog myFDlg(mLFont);

    if (myFDlg.DoModal() == IDOK)
    {

    // I am not sure if I need to create a new (clean) LOGFONT object

    if (mLFont != NULL)
    {
    delete mLFont;
    mLFont = NULL;
    }

    mLFont = new LOGFONT;
    memset(mLFont, 0, sizeof(LOGFONT));
    myFDlg.GetCurrentFont(mLFont);
    }
    -----

    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?

    Thanks,
    Kuphryn

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    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.

    Kuphryn

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21