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. setting the font of the view in the doc/ view architecture

setting the font of the view in the doc/ view architecture

Scheduled Pinned Locked Moved C / C++ / MFC
architecturetutorialquestion
6 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.
  • M Offline
    M Offline
    maxsteel
    wrote on last edited by
    #1

    i have a program done using the doc/view architecture. i want to change the font of whatever text i display in the view but am unable to figure out how to do so and in which member function of CView such as OnDraw, OnUpdate, etc?:confused:

    V 1 Reply Last reply
    0
    • M maxsteel

      i have a program done using the doc/view architecture. i want to change the font of whatever text i display in the view but am unable to figure out how to do so and in which member function of CView such as OnDraw, OnUpdate, etc?:confused:

      V Offline
      V Offline
      vikashparida
      wrote on last edited by
      #2

      Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida

      A M 3 Replies Last reply
      0
      • V vikashparida

        Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida

        A Offline
        A Offline
        Andrew Quinn AUS
        wrote on last edited by
        #3

        or are you on about controls in your view, e.g. CEdit's and CStatics ??? If so, then create a CFont object member in your view e.g. in OnInitialUpdate

         // m\_fntStyle1 is a CFont member of the view
         m\_fntStyle1.CreateFont(42, 0, 0, 0, FW\_BOLD, TRUE, FALSE,0,0,0,0,0,0, "Times New Roman");
        
         m\_staticField1.SetFont(&m\_fntStyle1);
         m\_staticField2.SetFont(&m\_fntStyle1);
         m\_staticField3.SetFont(&m\_fntStyle1);
         // etc
        

        The link to MSDN for CreateFont Hope this helps, Andy

        1 Reply Last reply
        0
        • V vikashparida

          Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida

          M Offline
          M Offline
          maxsteel
          wrote on last edited by
          #4

          thank you for ur help

          1 Reply Last reply
          0
          • V vikashparida

            Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida

            M Offline
            M Offline
            maxsteel
            wrote on last edited by
            #5

            hi, i tried to do as u told but the font does not change. CFont Font; CFont* pOldFont; LOGFONT lgFont; CTextFormatterDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); lgFont.lfHeight = -19; lgFont.lfWidth = 0; lgFont.lfWeight = FW_BOLD; lgFont.lfItalic = TRUE; lgFont.lfStrikeOut = TRUE; lgFont.lfUnderline = TRUE; lgFont.lfCharSet = ANSI_CHARSET; lgFont.lfOutPrecision = OUT_CHARACTER_PRECIS; lgFont.lfQuality = DEFAULT_QUALITY; strcpy(lgFont.lfFaceName, ""); Font.CreateFontIndirect(&lgFont); pOldFont = pDC->SelectObject(&Font); pDC->TextOut(0, 0, pDoc->GetText()); pDC->SelectObject(pOldFont); Font.DeleteObject();

            R 1 Reply Last reply
            0
            • M maxsteel

              hi, i tried to do as u told but the font does not change. CFont Font; CFont* pOldFont; LOGFONT lgFont; CTextFormatterDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); lgFont.lfHeight = -19; lgFont.lfWidth = 0; lgFont.lfWeight = FW_BOLD; lgFont.lfItalic = TRUE; lgFont.lfStrikeOut = TRUE; lgFont.lfUnderline = TRUE; lgFont.lfCharSet = ANSI_CHARSET; lgFont.lfOutPrecision = OUT_CHARACTER_PRECIS; lgFont.lfQuality = DEFAULT_QUALITY; strcpy(lgFont.lfFaceName, ""); Font.CreateFontIndirect(&lgFont); pOldFont = pDC->SelectObject(&Font); pDC->TextOut(0, 0, pDoc->GetText()); pDC->SelectObject(pOldFont); Font.DeleteObject();

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              maxsteel wrote: strcpy(lgFont.lfFaceName, ""); You need to give the name of the font ("Tahoma", "Times New Roman" etc...)

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              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