How do I make the button label bold in MFC?

I have a button in an MFC dialog. How do I make the text bold?

+1


a source to share


2 answers


You can create a new CFont and call the WM_SETFONT button on the button. Something like that:



// note: m_font is a class variable of type CFont
m_font.CreateFont(10, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Arial")
GetDlgItem(IDC_BUTTON1)->SendMessage(WM_SETFONT, WPARAM(HFONT(font)), 0);

      

+2


a source


class CYourDialog : CDialog
{
public:
   virtual BOOL OnInitDialog(); // override

private:
   CButton m_button;
   CFont m_font;
};

BOOL CYourDialog::OnInitDialog()
{
      __super::OnInitDialog();

      CFont* font = m_button.GetFont();

      LOGFONT logFont;
      font->GetLogFont(&logFont);
      logFont.lfWeight = FW_BOLD;

      m_font.CreateFontIndirect(&logFont);
      m_button.SetFont(&m_font);
}

      



+11


a source







All Articles