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 Background Colour of a text

Setting Background Colour of a text

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
2 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.
  • P Offline
    P Offline
    Pazzuzu
    wrote on last edited by
    #1

    Hi Guys, Iam working on Vc++, & came across a problem.Hope someone could help!. Iam Using device Context for diplaying things to the view. Initially,I write a "text" to the view using "TextOut" method - See Code: & Then using the "BRUSH" object to fill the rectangle with that colour,using "FillRect" method.Now the "text" which was displayed in the same postion before is not Visible anymore . My need ,is after writing a "Text" to the view & filling the rectangle containing the text with a colour,want the underlying "text" to be visible(which is not the case now). Ofcourse,I know that If I set the BackgroundColour atfirst & then write the "text" to the screen,then the "text" will be visible. But I would not be able to do so co's of some restrictions in my Project... I want the text "Shading test" to be displayed with the blue background colour.Constraint being,I can't Fill the rectangle with the colour & then draw the text..... Would be nice if someone could suggest something to do in this regard with respect to the code below. Thanks...... pDC->SetBkMode(TRANSPARENT); CRect rect; GetClientRect(rect); rect.SetRect(0,0,800,800); pDC->Rectangle(CRect(0,0,800,800)); SIZE size; size.cx = 1000; size.cy = 1000; SetScrollSizes(MM_TEXT,size); pDC->TextOut(50,20,"Shading Test"); CRect rect1; rect1.SetRect(10,10,300,100); pDC->Rectangle(CRect(10,10,300,100)); CBrush brushBlue(RGB(240,248,255)); CBrush* pOldBrush = pDC->SelectObject(&brushBlue); pDC->FillRect(rect1,&brushBlue);

    A 1 Reply Last reply
    0
    • P Pazzuzu

      Hi Guys, Iam working on Vc++, & came across a problem.Hope someone could help!. Iam Using device Context for diplaying things to the view. Initially,I write a "text" to the view using "TextOut" method - See Code: & Then using the "BRUSH" object to fill the rectangle with that colour,using "FillRect" method.Now the "text" which was displayed in the same postion before is not Visible anymore . My need ,is after writing a "Text" to the view & filling the rectangle containing the text with a colour,want the underlying "text" to be visible(which is not the case now). Ofcourse,I know that If I set the BackgroundColour atfirst & then write the "text" to the screen,then the "text" will be visible. But I would not be able to do so co's of some restrictions in my Project... I want the text "Shading test" to be displayed with the blue background colour.Constraint being,I can't Fill the rectangle with the colour & then draw the text..... Would be nice if someone could suggest something to do in this regard with respect to the code below. Thanks...... pDC->SetBkMode(TRANSPARENT); CRect rect; GetClientRect(rect); rect.SetRect(0,0,800,800); pDC->Rectangle(CRect(0,0,800,800)); SIZE size; size.cx = 1000; size.cy = 1000; SetScrollSizes(MM_TEXT,size); pDC->TextOut(50,20,"Shading Test"); CRect rect1; rect1.SetRect(10,10,300,100); pDC->Rectangle(CRect(10,10,300,100)); CBrush brushBlue(RGB(240,248,255)); CBrush* pOldBrush = pDC->SelectObject(&brushBlue); pDC->FillRect(rect1,&brushBlue);

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

      I suggest that you rework your code so that you can fill the background before writing the text out! Ant. I'm hard, yet soft.
      I'm coloured, yet clear.
      I'm fruity and sweet.
      I'm jelly, what am I? Muse on it further, I shall return!
      - David Walliams (Little Britain)

      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