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. SetFont for CWnd class [modified]

SetFont for CWnd class [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
5 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.
  • N Offline
    N Offline
    ns
    wrote on last edited by
    #1

    I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.

    LOGFONT lf;                        // Used to create the CFont.
    

    memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
    lf.lfHeight = 6; // Request a 6-pixel-high font
    strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
    m_font.CreateFontIndirect(&lf); // Create the font.

    m_grph.SetFont(&m_font);

    :confused: sb -- modified at 15:35 Wednesday 14th June, 2006

    D S H 3 Replies Last reply
    0
    • N ns

      I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.

      LOGFONT lf;                        // Used to create the CFont.
      

      memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
      lf.lfHeight = 6; // Request a 6-pixel-high font
      strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
      m_font.CreateFontIndirect(&lf); // Create the font.

      m_grph.SetFont(&m_font);

      :confused: sb -- modified at 15:35 Wednesday 14th June, 2006

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

      Does m_font belong to the CWnd-derived class? From where is SetFont() being called? There is an example in the Extras section of this article.


      "The largest fire starts but with the smallest spark." - David Crow

      "Judge not by the eye but by the heart." - Native American Proverb

      1 Reply Last reply
      0
      • N ns

        I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.

        LOGFONT lf;                        // Used to create the CFont.
        

        memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
        lf.lfHeight = 6; // Request a 6-pixel-high font
        strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
        m_font.CreateFontIndirect(&lf); // Create the font.

        m_grph.SetFont(&m_font);

        :confused: sb -- modified at 15:35 Wednesday 14th June, 2006

        S Offline
        S Offline
        see me
        wrote on last edited by
        #3

        Can you try CreatePointFont?????? The procedure is like this. // member CFont m_FontArial; // Create the font in Constructor m_FontArial.CreatePointFont( 140, PSIGL_CONTROL_FONT_TYPE_ARIAL ); pWindow->SetFont( &m_FontArial ); yours faithfully ajeeshcv

        N 1 Reply Last reply
        0
        • N ns

          I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.

          LOGFONT lf;                        // Used to create the CFont.
          

          memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
          lf.lfHeight = 6; // Request a 6-pixel-high font
          strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
          m_font.CreateFontIndirect(&lf); // Create the font.

          m_grph.SetFont(&m_font);

          :confused: sb -- modified at 15:35 Wednesday 14th June, 2006

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          im not sure your problem is this but m_font is global or no i saw if (m_font) isnt global it doesnt work i wrote a program and used like your code but font dosent change then i changed declare my variable from function to class and it worked._**


          **_

          whitesky


          1 Reply Last reply
          0
          • S see me

            Can you try CreatePointFont?????? The procedure is like this. // member CFont m_FontArial; // Create the font in Constructor m_FontArial.CreatePointFont( 140, PSIGL_CONTROL_FONT_TYPE_ARIAL ); pWindow->SetFont( &m_FontArial ); yours faithfully ajeeshcv

            N Offline
            N Offline
            ns
            wrote on last edited by
            #5

            Here is what worked for me:

            CClientDC dc(this);
            CFont l_font;
            l_font.CreateFont(14, 0, 0, 0, FW_NORMAL,
            FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

            CFont* l_old_font = dc.SelectObject(&l_font); dc.TextOut(50, 50, "Hello World");
            dc.SelectObject(l_old_font);
            // Delete the font object.
            l_font.DeleteObject();

            except that I got my CDC in the OnraseBackground function of the CStatic class. Thanks everyone for helping. sb

            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