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.
erebelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

luisrCommented:
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).
0
V_BapatCommented:
Derive your class from CFontDialog.
You can use the data member m_cf to modify font type, size etc before calling DoModal.
0
erebelAuthor Commented:
Details missing
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

spetrowitschCommented:
Hi.

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)
{
      //{{AFX_DATA_INIT(CCEDialog)
            // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
      //}}AFX_DATA_INIT

             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;
      
      CDialog::OnInitDialog();


      // 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)
      {
            font1.CreateFontIndirect(&m_logfont);
            fontStandard.CreateFontIndirect(&m_logfont);
            
            nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 12) / 72);
            m_logfont.lfHeight = nHeight;  
            m_logfont.lfWeight = FW_NORMAL;
            font0.CreateFontIndirect(&m_logfont);
            fontNormal.CreateFontIndirect(&m_logfont);

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

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

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


      for (hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL;
            hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)) {
                  CWnd::FromHandle(hWndChild)->SetFont(&font1);
      }
      FirstInit = FALSE;

      return TRUE;  
}



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


BEGIN_MESSAGE_MAP(CCEDialog, CDialog)
      //{{AFX_MSG_MAP(CCEDialog)
            // HINWEIS: Der Klassen-Assistent fügt hier Zuordnungsmakros für Nachrichten ein
        ON_WM_CTLCOLOR()
        ON_WM_HELPINFO()
            ON_WM_DESTROY()
        ON_COMMAND(WM_HELPDLG, OnHelpDlg)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CCEDialog


/*******************************************************************************
      OnCtlColor
      
      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()
{
      CDialog::OnDestroy();
      
      if (!FirstInit)
      {
            font0.DeleteObject();
            font1.DeleteObject();
            font2.DeleteObject();
            fontNormal.DeleteObject();
            fontStandard.DeleteObject();
            fontSmall.DeleteObject();
            fontLarge.DeleteObject();
            fontHuge.DeleteObject();
            backbrush.DeleteObject();
      }

}

/*******************************************************************************
      OnHelpInfo
      
      Erläuterungen:      Hilfeaufruf mit F1
*********************************************************************************/
BOOL CCEDialog::OnHelpInfo(HELPINFO* pHelpInfo)
{
      WinHelp(CEDlgHelpID);
      return TRUE;
}



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


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()
{
      WinHelp(CEDlgHelpID);
      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
public:
      CCEDialog(UINT nIDTemplate=NULL, CWnd* pParent = NULL);   // Standardkonstruktor


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


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

// Implementierung
private:
      int ColorStyle;
protected:

      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;
protected:
      void EnableGroup(int *groupField, BOOL do_enable);
      BOOL DoValidate(BOOL *Ptr);
      BOOL OnHelpDlg() ;
      // Generierte Nachrichtenzuordnungsfunktionen
      //{{AFX_MSG(CCEDialog)
      // 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();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
luisrCommented:
I'd say it's easier if you want the exact same font (but bold) to do something like in OnInitDialog:

CFont *pFont = GetFont();
LOGFONT lf;

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

// m_fontBold is a CFont data member
m_fontBold.CreateFontIndirect(&lf);

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

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

0
luisrCommented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.