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. How to change background color of CDialog and it's elements

How to change background color of CDialog and it's elements

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelp
3 Posts 3 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.
  • H Offline
    H Offline
    haritadala
    wrote on last edited by
    #1

    Hello all How do one should go about changing the background color of CDialog and its elements like buttons,group boxes etc. Pls help me with an example. Many thanks for your help. Hari.

    A 1 Reply Last reply
    0
    • H haritadala

      Hello all How do one should go about changing the background color of CDialog and its elements like buttons,group boxes etc. Pls help me with an example. Many thanks for your help. Hari.

      A Offline
      A Offline
      andreas schaerer
      wrote on last edited by
      #2

      hy, try to overwrite OnEraseBkg, and also OnCTLColor try something like this: HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { switch (nCtlColor) { case CTLCOLOR_STATIC: case CTLCOLOR_LISTBOX: case CTLCOLOR_BTN: pDC->SetBkColor(GetSysColor(COLOR_BTNFACE)); return (HBRUSH)m_grayBrushPtr->GetSafeHandle(); break; default: return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); break; } }

      S 1 Reply Last reply
      0
      • A andreas schaerer

        hy, try to overwrite OnEraseBkg, and also OnCTLColor try something like this: HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { switch (nCtlColor) { case CTLCOLOR_STATIC: case CTLCOLOR_LISTBOX: case CTLCOLOR_BTN: pDC->SetBkColor(GetSysColor(COLOR_BTNFACE)); return (HBRUSH)m_grayBrushPtr->GetSafeHandle(); break; default: return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); break; } }

        S Offline
        S Offline
        Shehzad Salim
        wrote on last edited by
        #3

        there is an easy was aswell take a variable of type CBrush at class level like CBrush m_Bursh; initiate it in OnInitDialog like m_Bursh.CreateSolidBrush(RGB(0,0,0));//OR ANY OTHER COLOR u WANT override the WM_CTCOLOR message handler and add this line to its implemention HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_Brush; }

        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