Solved

Background Color of GroupBox

Posted on 2000-02-23
9
1,552 Views
Last Modified: 2013-11-20
Hi
I have a group box and i want to sent the BackGround color of the Group box as white ,i tried to trap the WM_CTLCOLOR for it ,it doesn't work...is there any simple way to work it out..
Bhoomi
0
Comment
Question by:bhoomi_2000
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2551794
U have to derive UR class and map WM_CTLCOLOR to it and UR group box varible should be of that class type
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2552097
Are you trying to cange the background color of the interior of the group box?

..B ekiM
0
 

Author Comment

by:bhoomi_2000
ID: 2552271
Hi
Yeah i have my own derived Group Box,tried to MAP the WM_CTLCOLOR for it,but unfortunately , i don't get any messages of WM_CTLCOLOR for the derived Group box,and also in the Parent class...
Yeah I am trying to change the background color of the interior of the group box..
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2552835
Group boxes don't draw their interiors (AFAIK) .. just the border.

How about you put a white rectangle (static) control inside it.

0
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.

 

Author Comment

by:bhoomi_2000
ID: 2555492
If i place a static control ,white rectangle ,it overshadows other controls and the other controls which i listed in the group box is invisible
0
 

Author Comment

by:bhoomi_2000
ID: 2555493
If i place a static control ,white rectangle ,it overshadows other controls and the other controls which i listed in the group box is invisible
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 30 total points
ID: 2555618
A group box control draws its interior, just like most every other control in the world.

1) Create your own class with ClassWizard.  Call it, for example, CMyGroupBox. Base it on CStatic.

2) Add a handler for WM_ERASEBKGND to your class. Code something that paints the color you want. For example, you can do this:

BOOL CMyGroupBox::OnEraseBkgnd(CDC* pDC)
{
   CRect rect;
   GetClientRect(rect);

   CBrush brushBlue(RGB(0, 0, 255));
   CBrush* pOldBrush = pDC->SelectObject(&brushBlue);

   pDC->Rectangle(rect);
   pDC->SelectObject(pOldBrush);

   return TRUE;
}

3) Add an instance of CMyGroupBox to your dialog as member data.  For instance,

   CMyGroupBox m_box;

4) In OnInitDialog() of your dialog box, subclass the control. If your control's ID is IDC_MYBOX, then use:

   m_box.SubclassDlgItem(IDC_MYBOX, this);  

Note that you must have a real ID; you can't use IDC_STATIC.

That's it. Now, that OnEraseBkgnd() handler will paint the backgorund of the box.

Note that you might want to also handle WM_CTLCOLOR for the control in order to have the background of the label text (or even the text colour) look nice. Also, note that most controls paint opaque--so you might have to handle WM_CTLCOLOR for controls inside the box and set transparent mode on them to let your new background color show thru.

..B ekiM
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2556170
Mike: Doesn't a group box paint its interior with a hollow (or maybe null) brush?  If so (unless one is being pedantic), the group box effectively doesn't do anything to its interior (paints it with nothing).  That is the point I was trying to make.  Obviously I didn't succeed :-).

bhoomi: Whether or not the rectangle is under or over other control is a matter of dialog layout order.  You can easily control this yourself (Ctrl+D in resrouce/dialog editor).

Mike's suggestion seems to be the best.  Good idea Mike .. didn't think of deriving and doing the OnEraseBkgnd, although I've done similar things many times myself.

bhoomi: might also be worth your while looks at an MSJ article (May 1997 C/C++ Q & A) by Paul D'Lascia where he shows how to put a bitmap background on a dialog, and discusses all the ins and outs of how to make controls appear correctly over a non-standard background (which is what you'll need to do to make your white background look correct).

0
 

Author Comment

by:bhoomi_2000
ID: 2558619
HI MIKE AND RON
I think Ron and mikes both of your suggestion has to be combined for effective solution.But mike the other best way is to derive a own CStatic class and trap WM_CTLCOLOR message and paint the static control with required brush.Instead of handling WM_ERASEBACKGROUND,your suggestion also is an good alternative.


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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

15 Experts available now in Live!

Get 1:1 Help Now