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. Font problem

Font problem

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

    Hello, I'm changing a form background color using OnEraseBkgnd(CDC* pDC) I'm also drawing texto and using a CFont for the propose. The problem is when OnEraseBkgnd(CDC* pDC) is called the second time, i'm using the font like: VERIFY(hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold")); pOldFont=pDC->SelectObject(&hFont); pDC->SelectObject(hFont); pDC->DrawText(sFormName, -1, CRect(15, 0, rc.Width(),80), DT_LEFT|DT_SINGLELINE|DT_VCENTER); pDC->SelectObject(&pOldFont); But, after it exits the function i get an error. What am I doing wrong? Thank you for your time

    D 1 Reply Last reply
    0
    • R RuiSantiago

      Hello, I'm changing a form background color using OnEraseBkgnd(CDC* pDC) I'm also drawing texto and using a CFont for the propose. The problem is when OnEraseBkgnd(CDC* pDC) is called the second time, i'm using the font like: VERIFY(hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold")); pOldFont=pDC->SelectObject(&hFont); pDC->SelectObject(hFont); pDC->DrawText(sFormName, -1, CRect(15, 0, rc.Width(),80), DT_LEFT|DT_SINGLELINE|DT_VCENTER); pDC->SelectObject(&pOldFont); But, after it exits the function i get an error. What am I doing wrong? Thank you for your time

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      Hallo, Don't create the font resource in the OnEraseBkgnd(...). Create the font in a function, which is called only once or try this:

      if(hFont == NULL)
      {
      hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold"));
      }

      But the way better method is to make the font resource global and create it once, for example in the class'es constructor. And don't forget to release the font resource when exiting the program with DeleteObject. :-D -Dominik

      R 1 Reply Last reply
      0
      • D Dominik Reichl

        Hallo, Don't create the font resource in the OnEraseBkgnd(...). Create the font in a function, which is called only once or try this:

        if(hFont == NULL)
        {
        hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold"));
        }

        But the way better method is to make the font resource global and create it once, for example in the class'es constructor. And don't forget to release the font resource when exiting the program with DeleteObject. :-D -Dominik

        R Offline
        R Offline
        RuiSantiago
        wrote on last edited by
        #3

        Thank you Dominik for your advise, Well, the '==' operator dosen't work, because hFont is not a pointer. Is there a way to test if hFont was created? Now its Working fine, thank you very much

        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