Search code examples
c++visual-c++mfcvisual-c++-2012

Is there a way to change the title font for a MFC SDI application?


I am trying to increase the font size for the title on the MainFrame. So far, I have tried several approaches without a good result. Any suggestions are welcome.

A. Approach 1

    void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
    LOGFONT lF;
    lF.lfHeight = 10;
    lF.lfWidth = 0;
    lF.lfWeight = FW_NORMAL;
    lF.lfItalic = FALSE; //TRUE;
    lF.lfUnderline = FALSE; //TRUE;
    lF.lfStrikeOut = FALSE; //TRUE;
    lF.lfEscapement = 0;
    lF.lfOrientation = 0;
    _tcscpy_s(lF.lfFaceName, _T("Verdana"));

    CFont m_font;
    m_font.CreateFontIndirect(&lF);
    SetFont(&m_font);
       }

It doesn't change a thing.

B. Approach 2

     void CMainFrame::OnPaint()
     {
     CPaintDC dc(this); // device context for painting
    LOGFONT lF;
    lF.lfHeight = 10;
    lF.lfWidth = 0;
    lF.lfWeight = FW_NORMAL;
    lF.lfItalic = FALSE; //TRUE;
    lF.lfUnderline = FALSE; //TRUE;
    lF.lfStrikeOut = FALSE; //TRUE;
    lF.lfEscapement = 0;
    lF.lfOrientation = 0;
    _tcscpy_s(lF.lfFaceName, _T("Verdana"));

    CFont m_font;
    m_font.CreateFontIndirect(&lF);
    BOOL fRedraw = TRUE;
    SendMessageToDescendants(WM_SETFONT, (WPARAM)m_font.m_hObject);
      }

This approach deletes all my ribbon menus and creates a lot of exceptions.


Solution

  • You may want to look at this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb688195(v=vs.85).aspx

    However, as Mark Ransom suggested it is not easy.