Making A CStatics Text Go Bold
-
I am trying to make the text bold in a CStatic. I wrote the following code, Can anyone see where i am going wrong. CFont *M_titleFont is a member varible. Code Snippet, from oninitdialog: LOGFONT lf; m_titleFont= GetDlgItem(IDC_TITLE)->GetFont(); m_titleFont->GetLogFont(&lf); lf.lfWeight = 700; //Set Bold m_titleFont->CreateFontIndirect(&lf); Cheers Rich
-
I am trying to make the text bold in a CStatic. I wrote the following code, Can anyone see where i am going wrong. CFont *M_titleFont is a member varible. Code Snippet, from oninitdialog: LOGFONT lf; m_titleFont= GetDlgItem(IDC_TITLE)->GetFont(); m_titleFont->GetLogFont(&lf); lf.lfWeight = 700; //Set Bold m_titleFont->CreateFontIndirect(&lf); Cheers Rich
The problem is in the GetFont() call. MFC wrapps the HFONT in a temporary CFont object and when you call the CreateFontIndirect() a new HFONT is created in the temporary object and never gets back to the control. All you have to do is tell the control to use the new font, GetDlgItem( IDC_TITLE )->SetFont( m_titleFont );
-
The problem is in the GetFont() call. MFC wrapps the HFONT in a temporary CFont object and when you call the CreateFontIndirect() a new HFONT is created in the temporary object and never gets back to the control. All you have to do is tell the control to use the new font, GetDlgItem( IDC_TITLE )->SetFont( m_titleFont );