Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Background Color of GroupBox

Posted on 2000-02-23
9
Medium Priority
?
1,657 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
[X]
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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 

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 90 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 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