如何在MFC中将按钮标题加粗?

时间:2009-05-07 12:17:47

标签: visual-c++ mfc

我在MFC对话框上有一个按钮。如何使文字变粗?

2 个答案:

答案 0 :(得分:12)

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);

      return TRUE;  // => system will set input focus to the first control item in the dialog box; (0 => you set the focus to a control of your choice)
}

答案 1 :(得分:2)

您可以创建一个新字体并在按钮上调用WM_SETFONT。像这样:

// 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);