Solved

How to change color of dialog

Posted on 2006-11-30
8
245 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
8 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 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 250 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 44

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 44

Expert Comment

by:AndyAinscow
ID: 18372952
split
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

943 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now