How to create a bold and italic shortcut in MFC?

Please do not mark this as a hoax to this question:

MFC Bold Labels

This question does not help me; for some reason I don't see rich editing. Instead, I believe I should do this in code. here is the 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 reinvent the wheel and not experience errors on my own or through QA.

Someone had to realize this before. Please share your code.

What I would like to do:

  • Keep the same font size, family, etc., as in the already created shortcut, but make it bold and italic .
  • Make sure that the memory area is low enough (do not create new unnecessary objects), but do not get the application in an inconsistent state.

I appreciate your help.

+6
c ++ label mfc
source share
1 answer

You need to do the following before the static text control is shown in the parent window.

  • Get the window handle: CWnd * pwnd = GetDlgItem(IDC_LABEL);
  • Get the current font for static text: CFont * pfont = pwnd->GetFont();
  • Get font characteristics: LOGFONT lf; pfont->GetLogFont(&lf); LOGFONT lf; pfont->GetLogFont(&lf);
  • Change the lfWeight and lfItalic fields in lf .
  • Place the CFont object in the parent window so that it exists for the entire life cycle of the child window.
  • Initialize CFont: m_font.CreateFontIndirect(&lf);
  • Install the font in a static text box: pwnd->SetFont(&m_font);
+7
source share

All Articles