• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

fat font in CDialog and it´s controls

How can I change all text in my CDialog-Boxes and all it´s controls, also the text the user has to put into the controls,  into fat? Please give a detailed answer.
1 Solution
You have to create a CFont object with the properties you want (sorry, I have no docs available here, but set the weight to FW_BOLD) and then set it to all controls by sending WM_SETFONT message (or calling the equivalent MFC CWnd::SetFont).
Derive your class from CFontDialog.
You can use the data member m_cf to modify font type, size etc before calling DoModal.
erebelAuthor Commented:
Details missing
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.


I had a similar problem. Here is my source-code:

// CEDialog.h
// Dialog-Funktion

#include "stdafx.h"
#include "syslib.h"

CCEDialog::CCEDialog(UINT nIDTemplate, CWnd* pParent)
      : CDialog(nIDTemplate, pParent)
            // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein

             FirstInit = TRUE;
            // backbrush.CreateSolidBrush(RGB(255,255,255));
        CEDlgStyle = 9;
        CEDlgHelpID = 0x00003;
            CEExplorerHinweisID = 0;

      OnInitDialog -- Initializer

      Erläuterungen:               Font erstellen und setzen;
BOOL CCEDialog::OnInitDialog()
      LOGFONT m_logfont;          // font in use for the document
      HWND hWndChild;
      int nHeight;

      // Schriftgröße bestimmen      
      CPaintDC dc(this);          
      memset(&m_logfont, 0, sizeof m_logfont);
      nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 12) / 72);
      m_logfont.lfHeight = nHeight;   // -12
      static char BASED_CODE szArial[] = "Arial";
      lstrcpy(m_logfont.lfFaceName, szArial);
      m_logfont.lfOutPrecision = OUT_TT_PRECIS;
      m_logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
      m_logfont.lfQuality = PROOF_QUALITY;
      m_logfont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
    m_logfont.lfWeight = (CEDlgStyle>=9) ? FW_NORMAL : FW_BOLD;
      if (FirstInit)
            nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 12) / 72);
            m_logfont.lfHeight = nHeight;  
            m_logfont.lfWeight = FW_NORMAL;

            nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 16) / 72);
            m_logfont.lfHeight = nHeight;  
            m_logfont.lfWeight = FW_BOLD;

            nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 20) / 72);
            m_logfont.lfHeight = nHeight;  
            m_logfont.lfWeight = FW_BOLD;

            nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 9) / 72);
            m_logfont.lfHeight = nHeight;  
            m_logfont.lfWeight = FW_NORMAL;

      for (hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL;
            hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)) {
      FirstInit = FALSE;

      return TRUE;  

void CCEDialog::DoDataExchange(CDataExchange* pDX)
            // HINWEIS: Der Klassen-Assistent fügt hier DDX- und DDV-Aufrufe ein

            // HINWEIS: Der Klassen-Assistent fügt hier Zuordnungsmakros für Nachrichten ein

// Behandlungsroutinen für Nachrichten CCEDialog

      Erläuterungen:      Hintergrundfarbe einstellen.
HBRUSH CCEDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      return hbr;

void CCEDialog::OnDestroy()
      if (!FirstInit)


      Erläuterungen:      Hilfeaufruf mit F1
BOOL CCEDialog::OnHelpInfo(HELPINFO* pHelpInfo)
      return TRUE;

void CCEDialog::EnableGroup(int *groupField, BOOL do_enable)
      int i=0;
      while (groupField[i])
            if (!do_enable && 
                  GetDlgItem(groupField[i])->IsKindOf( RUNTIME_CLASS( CEdit ) ))
             if (!do_enable && 
                  GetDlgItem(groupField[i])->IsKindOf( RUNTIME_CLASS( CButton ) ))
                   ((CButton*)GetDlgItem(groupField[i]))->SetCheck(0);  // funktioniert nicht??????

BOOL CCEDialog::DoValidate(BOOL *Ptr)
      CWnd *cwndChild;
      BOOL (*FuncPtr) (int fldID);

      TRACE("Eintritt in Validate (CEDialog)\n");

      for (cwndChild = GetTopWindow(); cwndChild != NULL;
            cwndChild = cwndChild->GetNextWindow())
            if (cwndChild->IsWindowEnabled())
                  if (FuncPtr(cwndChild->GetDlgCtrlID()))
                        return FALSE;
      return TRUE;

BOOL CCEDialog::OnHelpDlg()
      return TRUE;

.... and here my .h-file:

// CEDialog
#define WM_WEITER 102
#define WM_HELPDLG 103
#define WM_DOCCHANGED 104
#define WM_DOCPRINT 105
#define WM_DOCSAVE 106
#define WM_DOCSHOW 107

// Dialogfeld CCEDialog

class CCEDialog : public CDialog
// Konstruktion
      CCEDialog(UINT nIDTemplate=NULL, CWnd* pParent = NULL);   // Standardkonstruktor

// Dialogfelddaten
//      enum { IDD = IDD_DIALOG2 };
            // HINWEIS: Der Klassen-Assistent fügt hier Datenelemente ein

// Überschreibungen
      // Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung

// Implementierung
      int ColorStyle;

      int CEDlgStyle;
      int CEDlgHelpID;
      int CEExplorerFrame;
      CString CEExplorerText;
      int CEExplorerHinweisID;

      BOOL FirstInit;

      CFont font0;            // Normal      
      CFont font1;            // Standard
      CFont font2;            // Large

      CFont fontNormal;      // Normal      
      CFont fontStandard;      // Standard
      CFont fontLarge;      // Large
      CFont fontHuge;            // z.B. für Explorer-Control
      CFont fontSmall;      // Small
      CBrush backbrush;
      void EnableGroup(int *groupField, BOOL do_enable);
      BOOL DoValidate(BOOL *Ptr);
      BOOL OnHelpDlg() ;
      // Generierte Nachrichtenzuordnungsfunktionen
      // HINWEIS: Der Klassen-Assistent fügt hier Member-Funktionen ein
        virtual BOOL OnInitDialog();
        afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
         afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
      afx_msg void OnDestroy();
I'd say it's easier if you want the exact same font (but bold) to do something like in OnInitDialog:

CFont *pFont = GetFont();

pFont->GetObject(sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;

// m_fontBold is a CFont data member

// Now call SetFont(m_fontBold) for
// every control you want with bold font

And don't forget to delete the font in OnDestroy.

Another thing that might help:

If you want to do it for every control, add this code in your OnInitDialog handler:

// m_fontBold was created with my previous code
::EnumChildWindows(m_hWnd, EnumChildPorc, (LPARAM) &m_fontBold);

and define your function EnumChildProc:

BOOL CALLBACK EnumChildProc( HWND hwnd, LPARAM lParam)
    CWnd *pWnd = CWnd::FromHandle(hwnd);
    pWnd->SetFont((CFont *) lParam);
    return TRUE;

and that's it!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now