?
Solved

How to change color of dialog

Posted on 2006-11-30
8
Medium Priority
?
254 Views
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.
0
Comment
Question by:Anisha
  • 3
5 Comments
 
LVL 45

Accepted Solution

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

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
{
  CRect rc;
  GetClientRect(&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
}
0
 
LVL 22

Assisted Solution

by:mahesh1402
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;
  GetClientRect(&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
}

//OR

BOOL CMyDialog::OnEraseBkgnd(CDC *pDC)
{
  CRect rect;
  GetClientRect(&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

-MAHESH
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 18044832
oops.
0
 
LVL 2

Expert Comment

by:AshvinPatel
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;
else
return hbr;
      
}

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

MiBrush.CreateSolidBrush(RGB(236,233,216));

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 18372952
split
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

850 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