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. How to change font of Labels in CDialog ?

How to change font of Labels in CDialog ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
9 Posts 3 Posters 1 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.
  • V Offline
    V Offline
    vgrigor
    wrote on last edited by
    #1

    I want to change font of static labels in CDialog, to Bold I think it need be dont in OnCtlColor, by getting font from CDC changing and SelectObject(font) from it. But when I try toget current font as CFont* pOldFont = pDC->SelectObject(&TmpFont); that returns NULL; But label is written by some font ? How to get it? And command to change ? thanks

    A M 2 Replies Last reply
    0
    • V vgrigor

      I want to change font of static labels in CDialog, to Bold I think it need be dont in OnCtlColor, by getting font from CDC changing and SelectObject(font) from it. But when I try toget current font as CFont* pOldFont = pDC->SelectObject(&TmpFont); that returns NULL; But label is written by some font ? How to get it? And command to change ? thanks

      A Offline
      A Offline
      Antony M Kancidrowski
      wrote on last edited by
      #2

      I'll have to say it may be better to have a owner drawn CStatic control. Try this http://www.codeproject.com/staticctrl/clabel.asp?target=CLabel[^] This is a very good class written by Norm Almond. Um, I think I have suggested this before.. Hope people don't think there is any favouritism here :laugh: Ant.

      V 1 Reply Last reply
      0
      • A Antony M Kancidrowski

        I'll have to say it may be better to have a owner drawn CStatic control. Try this http://www.codeproject.com/staticctrl/clabel.asp?target=CLabel[^] This is a very good class written by Norm Almond. Um, I think I have suggested this before.. Hope people don't think there is any favouritism here :laugh: Ant.

        V Offline
        V Offline
        vgrigor
        wrote on last edited by
        #3

        thanks you . For not to make many classes - does my version of working is not possible or where incorrect?

        1 Reply Last reply
        0
        • V vgrigor

          I want to change font of static labels in CDialog, to Bold I think it need be dont in OnCtlColor, by getting font from CDC changing and SelectObject(font) from it. But when I try toget current font as CFont* pOldFont = pDC->SelectObject(&TmpFont); that returns NULL; But label is written by some font ? How to get it? And command to change ? thanks

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          You can simply send a WM_SETFONT message. However, the font object is not copied by the control - it uses the object handle you sent. You need to keep the object around at least as long as the control(s) which use it. Stability. What an interesting concept. -- Chris Maunder

          V 1 Reply Last reply
          0
          • M Mike Dimmick

            You can simply send a WM_SETFONT message. However, the font object is not copied by the control - it uses the object handle you sent. You need to keep the object around at least as long as the control(s) which use it. Stability. What an interesting concept. -- Chris Maunder

            V Offline
            V Offline
            vgrigor
            wrote on last edited by
            #5

            To whom I must send this message ? To Label ?

            A 1 Reply Last reply
            0
            • V vgrigor

              To whom I must send this message ? To Label ?

              A Offline
              A Offline
              Antony M Kancidrowski
              wrote on last edited by
              #6

              I Mike means 1) Create a CFont object within the dialog (member variable). 2) Use GetDlgItem() to get the window of the static 3) Use SetFont() to set the font of the static object. As long as the CFont item is there for the duration of the dialog it will be there for the duration of the dialogs controls. This solution requires you to do all the work in the dialog. Ant.

              V 1 Reply Last reply
              0
              • A Antony M Kancidrowski

                I Mike means 1) Create a CFont object within the dialog (member variable). 2) Use GetDlgItem() to get the window of the static 3) Use SetFont() to set the font of the static object. As long as the CFont item is there for the duration of the dialog it will be there for the duration of the dialogs controls. This solution requires you to do all the work in the dialog. Ant.

                V Offline
                V Offline
                vgrigor
                wrote on last edited by
                #7

                Thanks you. Where to call it better ? In OnInitDialog() ?

                A 1 Reply Last reply
                0
                • V vgrigor

                  Thanks you. Where to call it better ? In OnInitDialog() ?

                  A Offline
                  A Offline
                  Antony M Kancidrowski
                  wrote on last edited by
                  #8

                  Yea InitDialog is fine:-D Ant.

                  V 1 Reply Last reply
                  0
                  • A Antony M Kancidrowski

                    Yea InitDialog is fine:-D Ant.

                    V Offline
                    V Offline
                    vgrigor
                    wrote on last edited by
                    #9

                    I will try. Thanks.

                    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