Changing the background color of a dialog


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

If you want to change the background color of your dialog box, it is a very simple.

In your CTestDlg header file, declare a member variable from CBrush:

class CTestDlg : public CDialog
 CBrush m_brush; 
Then, add this line in the OnInitDialog function:

BOOL CTestDlg::OnInitDialog() 
 m_brush.CreateSolidBrush(RGB(255, 255, 255)); // color white brush 
Finally do this on the ID_CTLCOLOR handle:

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
** No need to do this!
** HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

** Return the white brush.
return m_brush;
Hope this could help any fellow programmer!

Date Last Updated: February 8, 1999


  • What about ::AfxMessageBox or CWnd::MessageBox

    Posted by Legacy on 02/24/2004 08:00am

    Originally posted by: Its not a toomah!

    I want to also change the background of ::AfxMessageBox or CWnd::MessageBox.

    Can anybody here tell me how to do this?


  • Background color of dialog

    Posted by Legacy on 11/26/2003 08:00am

    Originally posted by: Aqualung

    It's much easier to do the following in the InitInstance:


    • SetDialogBkColor problem??

      Posted by break; on 07/01/2009 03:43pm

      Hi, SetDialogBkColor dont work in my project, and i dont know why?? :( Any idea for this? regards break;

  • thanks a lot,and a piece of advice

    Posted by Legacy on 10/22/2003 07:00am

    Originally posted by: Alex

    I am wondering about control background color changing. Through effect I find those methods mentioned in this article can change only color of text and dialog background.If we want to change the color of control,we must override the control class indivisually and rewrite their functions like DrawItem ,etc.
    Welcome comments about this opinion.

  • Alternate simple ways to change the dialog background color

    Posted by Legacy on 09/22/2003 07:00am

    Originally posted by: Jes

    BOOL CJesDialog::OnEraseBkgnd( CDC* pDC )
    CRect rectPage;

    GetClientRect(rectPage.operator LPRECT());

    // m_brDlgColor is CBrush object and should have created
    // in OnInitDialog
    pDC->FillRect(rectPage.operator LPRECT(),
    pDC->DrawText(CString("Jes"),rectPage.operator LPRECT(),

    return TRUE;

    or simply

    void CJesDialog::OnPaint()

    CPaintDC dc(this);

    dc.FillRect(m_rectGUI.operator LPRECT(),&m_brDlgColor);

    // you may retain code for drawing Icon; But never
    // allow to call CDialog::OnPaint()

  • How to Change MessageBox Background?

    Posted by Legacy on 02/07/2003 08:00am

    Originally posted by: Anand Shah

    Hi the code mentioned does not work for Message Box's.
    Can anyone help with changing the Background color of the MessageBox.

    • How to Change MessageBox Background?

      Posted by Mark Veldt on 05/15/2004 03:07am

      Search for Q99808 in Google. Microsoft has an example

  • I have a concern

    Posted by Legacy on 12/05/2002 08:00am

    Originally posted by: Deandrea Venon

    I need information on creating an atm application.
    The user should be able to enter deposit and withdrawal.
    In the end closing balance would be shown
    i have attempted it but it displays anassertion error. then everything in the dialog becomes blank. Please help!!

  • OK How to do it on a multi form app??

    Posted by Legacy on 05/30/2002 07:00am

    Originally posted by: javajunkie

    I have an app I would like to have the option of colors on each of 7 or 8 different forms that are CRecordViews. I can get the first form color changed but not the rest of them. I am using the OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) method. Any ideas on how to make all the forms have the background color changed?
    I know this isn't much deatil but if someone thinks they have a way I can provide the details for them.


  • How can I change check box's color and radio button color

    Posted by Legacy on 05/01/2002 07:00am

    Originally posted by: cthSon

    Button, radio and checkbox do not chang color

  • Can't change bgcolor of messageboxes.

    Posted by Legacy on 04/09/2002 07:00am

    Originally posted by: Pkun

    It does not work for messageboxes. How can I change messagebox's background?

  • thank you

    Posted by Legacy on 03/08/2002 08:00am

    Originally posted by: linxiao

    It really work!

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date