How to change color of dialog

Posted on 2006-11-30
Medium Priority
Last Modified: 2013-11-20
I have 2 dialogs which are docked to the bottom & left side of my window. These dialogs have a list control & tree control resp. I want to know how to change the color of these dialogs to light blue.
Question by:Anisha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 44

Accepted Solution

AndyAinscow earned 1000 total points
ID: 18044660
Trap the WM_ERASEBKGND message

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
  CRect rc;
  pDC->FillSolidRect(RGB(0, 0, 128));  //change the values to give the colour you want
  return TRUE;   //IMPORTANT else it will not be changed
LVL 22

Assisted Solution

mahesh1402 earned 1000 total points
ID: 18044784
What AndyAinscow suggested is right but with just a syntax error..

it should be like pDC->FillSolidRect(&rc,RGB(0, 0, 128)); //use &rc to input client rect

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
  CRect rc;
  pDC->FillSolidRect(&rc,RGB(0, 0, 128));  //change the values to give the colour you want
  return TRUE;   //IMPORTANT else it will not be changed


BOOL CMyDialog::OnEraseBkgnd(CDC *pDC)
  CRect rect;
  CBrush myBrush(RGB(255,0,0)); // Solid RED for instance
  CBrush *pOld = pDC->SelectObject(&myBrush);
  BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  pDC->SelectObject(pOld); // Have to restore old brush
  return bRes;

OR http://support.microsoft.com/default.aspx?scid=kb;EN-US;q115087

LVL 44

Expert Comment

ID: 18044832

Expert Comment

ID: 18107262
add a function wm_ctlcolor handlerr to class by right click on theclass name 'add window msg handler'
now modify the code like this

HBRUSH CLASSNAME::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
// return MiBrush;      CDialog MiDlg;
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, CTLCOLOR_DLG);

      if(nCtlColor==CTLCOLOR_DLG )
 return MiBrush;
return hbr;

define the object of the brush as "MiBrush "
write the
line of code in the oninitdialog()


LVL 44

Expert Comment

ID: 18372952

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question