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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Font/FontSize

Font/FontSize

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 4 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.
  • C Offline
    C Offline
    C NewBe
    wrote on last edited by
    #1

    I'm tring to set the Font and Fontsize to "MS Sans Serif" and 14, the code below does not seem to do it...what am I doing wrong? Is there an easier way to do this? Thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

    C CPalliniC D 3 Replies Last reply
    0
    • C C NewBe

      I'm tring to set the Font and Fontsize to "MS Sans Serif" and 14, the code below does not seem to do it...what am I doing wrong? Is there an easier way to do this? Thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You never initialize LargeFont. Why don't you use CFont::CreatePointFont ?

      Cédric Moonen Software developer
      Charting control [v1.3]

      1 Reply Last reply
      0
      • C C NewBe

        I'm tring to set the Font and Fontsize to "MS Sans Serif" and 14, the code below does not seem to do it...what am I doing wrong? Is there an easier way to do this? Thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        As addendum to Cédric reply, please note you probably have to use

        lf.lfHeight = -MulDiv(24, GetDeviceCaps(hDC, LOGPIXELSY), 72);

        to obtain a 24 point sized font. See [^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • C C NewBe

          I'm tring to set the Font and Fontsize to "MS Sans Serif" and 14, the code below does not seem to do it...what am I doing wrong? Is there an easier way to do this? Thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          C++NewBe wrote:

          CFont LargeFont;

          Where is this object declared?

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          C 1 Reply Last reply
          0
          • D David Crow

            C++NewBe wrote:

            CFont LargeFont;

            Where is this object declared?

            "Love people and use things, not love things and use people." - Unknown

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            C Offline
            C Offline
            C NewBe
            wrote on last edited by
            #5

            The original Post was missing this: VERIFY(LargeFont.CreateFontIndirect(&lf));

            D 1 Reply Last reply
            0
            • C C NewBe

              The original Post was missing this: VERIFY(LargeFont.CreateFontIndirect(&lf));

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Ok, but that did not answer my question. Is your problem solved now?

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              C 1 Reply Last reply
              0
              • D David Crow

                Ok, but that did not answer my question. Is your problem solved now?

                "Love people and use things, not love things and use people." - Unknown

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                C Offline
                C Offline
                C NewBe
                wrote on last edited by
                #7

                This is my code....what am I missing? I thing it's the height and weight that is giving me problem. I am from VB world. thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); VERIFY(LargeFont.CreateFontIndirect(&lf)); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

                D 1 Reply Last reply
                0
                • C C NewBe

                  This is my code....what am I missing? I thing it's the height and weight that is giving me problem. I am from VB world. thanks CFont LargeFont; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 24; lf.lfWeight = 400; strcpy(lf.lfFaceName, "MS Sans Serif"); VERIFY(LargeFont.CreateFontIndirect(&lf)); GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  C++NewBe wrote:

                  CFont LargeFont;

                  Where is this object declared? If it is not global, or is not a member of the dialog, it will go out of scope before SetFont() has a chance to work.

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  C 1 Reply Last reply
                  0
                  • D David Crow

                    C++NewBe wrote:

                    CFont LargeFont;

                    Where is this object declared? If it is not global, or is not a member of the dialog, it will go out of scope before SetFont() has a chance to work.

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    C Offline
                    C Offline
                    C NewBe
                    wrote on last edited by
                    #9

                    Now I understand....it is being declared on ::Paint()

                    D 1 Reply Last reply
                    0
                    • C C NewBe

                      Now I understand....it is being declared on ::Paint()

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      C++NewBe wrote:

                      it is being declared on ::Paint()

                      Therein lies the problem.

                      "Love people and use things, not love things and use people." - Unknown

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      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