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.

4
  • 1
    If you are not using a rich edit control, what kind of control are you using? Static text? Apr 13, 2010 at 17:58
  • 1
    Yes, a label, aka static text. Thanks for the question. Apr 13, 2010 at 17:59
  • 2
    Also, I find your "I don't want to do any work, give me the code" attitude to be very rude. Apr 13, 2010 at 18:01
  • 1
    @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. Apr 13, 2010 at 18:03

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.