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. CStatic background color problem

CStatic background color problem

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

    I am writing a program that displays static text on a black background. I can change the CStatic object backgound color to black or I can set the space behind the text to the standard light grey color I.E the space directly behind the text not the entire CStatic area (toggle m_staticTextBgd see below). I want to change this light grey to another color. I tried SetSysColors but I dont want to change this at a system level. Thanks if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = this->GetDC()->GetPixel(Rect.left-1, Rect.top-1); DeleteObject(hbr); hbr = CreateSolidBrush(Clr); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } return hbr; ---

    P 1 Reply Last reply
    0
    • C Coremn

      I am writing a program that displays static text on a black background. I can change the CStatic object backgound color to black or I can set the space behind the text to the standard light grey color I.E the space directly behind the text not the entire CStatic area (toggle m_staticTextBgd see below). I want to change this light grey to another color. I tried SetSysColors but I dont want to change this at a system level. Thanks if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = this->GetDC()->GetPixel(Rect.left-1, Rect.top-1); DeleteObject(hbr); hbr = CreateSolidBrush(Clr); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } return hbr; ---

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      Coremn wrote: COLORREF Clr = this->GetDC()->GetPixel(Rect.left-1, Rect.top-1); Coremn wrote: hbr = CreateSolidBrush(Clr); Coremn wrote: return hbr; You retruning the brush with the old screen color rite, then how is the color going to change ?


      "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

      C 1 Reply Last reply
      0
      • P Prakash Nadar

        Coremn wrote: COLORREF Clr = this->GetDC()->GetPixel(Rect.left-1, Rect.top-1); Coremn wrote: hbr = CreateSolidBrush(Clr); Coremn wrote: return hbr; You retruning the brush with the old screen color rite, then how is the color going to change ?


        "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

        C Offline
        C Offline
        Coremn
        wrote on last edited by
        #3

        Mr.Prakash wrote: return hbr; You retruning the brush with the old screen color rite, then how is the color going to change ? hbr is the background screen color, in my case black. This colors in the excess space in the CStatic where there is no text, I.E making the unused space blend in with the background, I want the space behind the actual text to be colored, this is done by not using pDC->SetBkColor(Clr); in the method OnCtlColor. But I dont know how to change this from light gray. ---

        P 1 Reply Last reply
        0
        • C Coremn

          Mr.Prakash wrote: return hbr; You retruning the brush with the old screen color rite, then how is the color going to change ? hbr is the background screen color, in my case black. This colors in the excess space in the CStatic where there is no text, I.E making the unused space blend in with the background, I want the space behind the actual text to be colored, this is done by not using pDC->SetBkColor(Clr); in the method OnCtlColor. But I dont know how to change this from light gray. ---

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          pDC->SetBkMode(TRANSPARENT) will do the trick.


          "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

          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