I have a button on an MFC dialog. How can I make the text bold?
我在MFC对话框上有一个按钮。如何使文字变粗?
2 个解决方案
#1
You can create a new CFont and call WM_SETFONT on the button. Something like this:
您可以创建一个新的CFont并在按钮上调用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);
#2
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
You can create a new CFont and call WM_SETFONT on the button. Something like this:
您可以创建一个新的CFont并在按钮上调用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);
#2
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)
}