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. changing the color of my controls to white using OnCtlColor

changing the color of my controls to white using OnCtlColor

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

    I want my dialog backgroung color to be grey thus i'm using OnCtlColor event but the problem is that the controls like combo box or edit control are also geting colored with grey. Please tell me how can i change the color of my controls to white???? i used the below code where CBrush m_Brush; HBRUSH CCTLColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkColor(RGB(210,209,213)); //if(pWnd->GetDlgCtrlID() == IDC_COMBO1) //{ pDC->SetBkColor(RGB(0,0,0)); //} //if(pWnd->GetDlgCtrlID() == IDC_EDIT1) //{ pDC->SetBkColor(RGB(0,0,0)); //} return m_Brush; } BOOL CCTLColorDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Brush.CreateSolidBrush(RGB(210,209,213)); return TRUE; // return TRUE unless you set the focus to a control }

    C 1 Reply Last reply
    0
    • B brucewayn

      I want my dialog backgroung color to be grey thus i'm using OnCtlColor event but the problem is that the controls like combo box or edit control are also geting colored with grey. Please tell me how can i change the color of my controls to white???? i used the below code where CBrush m_Brush; HBRUSH CCTLColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkColor(RGB(210,209,213)); //if(pWnd->GetDlgCtrlID() == IDC_COMBO1) //{ pDC->SetBkColor(RGB(0,0,0)); //} //if(pWnd->GetDlgCtrlID() == IDC_EDIT1) //{ pDC->SetBkColor(RGB(0,0,0)); //} return m_Brush; } BOOL CCTLColorDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Brush.CreateSolidBrush(RGB(210,209,213)); return TRUE; // return TRUE unless you set the focus to a control }

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      If you check out the documentation[^], you learn that the nCtlColor parameter tells you what is asking for the color, so you can filter out the queries.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      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