Solved

Background Color of GroupBox

Posted on 2000-02-23
9
1,530 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 78
Separate into files by filename 12 67
post4 challenge 28 83
Thin secure Windows 10 5 48
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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

706 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

13 Experts available now in Live!

Get 1:1 Help Now