Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Making A CStatics Text Go Bold

Making A CStatics Text Go Bold

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AJ123
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • A AJ123

      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

      D Offline
      D Offline
      Doug Garno
      wrote on last edited by
      #2

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

      A 1 Reply Last reply
      0
      • D Doug Garno

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

        A Offline
        A Offline
        AJ123
        wrote on last edited by
        #3

        Cheers! That was driving me up the wall!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups