6
votes

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.

1
If you are not using a rich edit control, what kind of control are you using? Static text? - Mark Ransom
Yes, a label, aka static text. Thanks for the question. - Hamish Grubijan
Also, I find your "I don't want to do any work, give me the code" attitude to be very rude. - Mark Ransom
@Mark, I can understand that. How can I phrase it better? I am just entering into the world of MFC and I have a tight deadline. I am not comfortable with it. I do believe that someone has a very good solution already. - Hamish Grubijan

1 Answers

8
votes

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