Solved

Background Color of GroupBox

Posted on 2000-02-23
9
1,566 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 92
Error on moodle after upgrade 3 130
deburging in oracle form 12 99
haveThree challenge 22 118
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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 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