7

Please do not mark it as a dupe of this question just yet:

Bold labels in MFC

That question does not help me; for some reason I do not see the rich edit control. Instead I believe I have to do it in code. here is a sample I found:

http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2006-10/msg00245.html

My problem is that I prefer not to re-invent the wheel and test for errors myself or through QA.

Someone must have implemented this before. Please share your code.

What I would like to do is:

  • Keep the same font size, family, etc. as in the already created label, but make it bold and italic as well.
  • Keep the memory footprint reasonably low (do not create any new unnecessary objects), but do not get the app into an inconsistent state either.

I appreciate your help.

Community
  • 1
  • 1
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147

1 Answers1

8

You will want to do the following before the static text control is shown on the parent window.

  1. Get a handle to the window: CWnd * pwnd = GetDlgItem(IDC_LABEL);
  2. Get the current font for the static text: CFont * pfont = pwnd->GetFont();
  3. Get the characteristics of the font: LOGFONT lf; pfont->GetLogFont(&lf);
  4. Change the lfWeight and lfItalic fields in lf.
  5. Put a CFont object in your parent window, so it will exist for the entire lifetime of the child window.
  6. Initialize the CFont: m_font.CreateFontIndirect(&lf);
  7. Set the font into the static text window: pwnd->SetFont(&m_font);
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622