Solved

How to change color of dialog

Posted on 2006-11-30
8
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
oops.
0
 
LVL 2

Expert Comment

by:AshvinPatel
Comment Utility
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
Comment Utility
split
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

10 Experts available now in Live!

Get 1:1 Help Now