tags:

views:

543

answers:

2

I have a button on an MFC dialog. How can I make the text bold?

+2  A: 

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

// 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);
djeidot
Of course you should do a GetFont() -> GetLogFont() of the button, modify LOGFONT structure's lfWeight property and create a new font based on it.
macbirdie
thanks @macbirdie, exactly what I was about to follow up with
Aidan Ryan
+2  A: 
class CYourDialog : CDialog
{
public:
   virtual BOOL OnInitDialog(); // override

private:
   CButton m_button;
   CFont m_font;
};

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

      CFont* font = m_button.GetFont();

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

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