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. C / C++ / MFC
  3. Coloring text in an ATL Control

Coloring text in an ATL Control

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

    I am working on an ATL control that has a simple CStatic text label. While I've managed to change the font in both OnInitDialog and OnPaint I cannot change the color. Basically it is a Property Sheet with a CStatic control on it. In the Constructor m_pArial is defined as: m_pArial->CreateFont(40, 0, 0, 0, 700, 0, 0, 0, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, "Arial"); And it is deleted in the destructor. Here is my code (it sets the font just fine - not the color). void CPropPage::OnPaint() { CPaintDC dc(this); // device context for painting CPen *pOldPen; CPen BluePen; BluePen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); CBrush Brush(RGB(0, 0, 255)); CBrush *pOldBrush; pOldPen = dc.SelectObject(&BluePen); pOldBrush = dc.SelectObject(&Brush); m_Static_Title.SetFont(m_pArial); m_Static_Title.SetWindowText("Test"); dc.SelectObject(pOldPen); dc.SelectObject(pOldBrush); } Thank You

    E 1 Reply Last reply
    0
    • L lpvoid

      I am working on an ATL control that has a simple CStatic text label. While I've managed to change the font in both OnInitDialog and OnPaint I cannot change the color. Basically it is a Property Sheet with a CStatic control on it. In the Constructor m_pArial is defined as: m_pArial->CreateFont(40, 0, 0, 0, 700, 0, 0, 0, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, "Arial"); And it is deleted in the destructor. Here is my code (it sets the font just fine - not the color). void CPropPage::OnPaint() { CPaintDC dc(this); // device context for painting CPen *pOldPen; CPen BluePen; BluePen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); CBrush Brush(RGB(0, 0, 255)); CBrush *pOldBrush; pOldPen = dc.SelectObject(&BluePen); pOldBrush = dc.SelectObject(&Brush); m_Static_Title.SetFont(m_pArial); m_Static_Title.SetWindowText("Test"); dc.SelectObject(pOldPen); dc.SelectObject(pOldBrush); } Thank You

      E Offline
      E Offline
      Erik Thompson
      wrote on last edited by
      #2

      You need to do it in the WM_CTLCOLORSTATIC message handler From MSDN on WM_CTLCOLORSTATIC: "A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control." Cheers, -Erik ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ My thoughts are my own and reflect on no other.

      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