Transparent Group Box Control | CodeGuru

Transparent Group Box Control

. Environment: Windows NT4 SP4 (German version), Visual C++ 6 SP2 If you make a dialog with a bitmap as background, you’ll probably handle WM_CTLCOLOR + CTLCOLOR_STATIC to set a transparent background for text items. This works fine except with groupboxes: if the text is transparent the group rectangle goes right through your text, which […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 1, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

.

Environment: Windows NT4 SP4 (German version), Visual C++ 6 SP2

If you make a dialog with a bitmap as background, you’ll probably handle
WM_CTLCOLOR + CTLCOLOR_STATIC to set a transparent background for text items.

This works fine except with groupboxes: if the text is transparent the
group rectangle goes right through your text, which looks BAD.

To make it look better, use this class CTGroupBox. It draws every side
of the box rectangle using LineTo’s and takes care of the text position
and extent.

Usage is simple: just give your group boxes unique IDs (instead of IDC_STATIC)
and then subclass them in OnInitDialog:

// in your .cpp file
void CMyBitmappedDialog::OnInitDialog()
{
 // I’m using Joerg Koenigs CBitmapDialog class 
 // (see Dialog section of CodeGuru for more info)
 CBitmapDialog::OnInitDialog();
 m_TGrpBox1.SubclassDlgItem(IDC_GRPBOX1, this);
 m_TGrpBox2.SubclassDlgItem(IDC_GRPBOX2, this);
 //…
 return TRUE;
}
// in your .h file
#include “TGroupBox.h”
class CMyBitmappedDialog : public CBitmapDialog
{
private:
 CTGroupBox m_TGrpBox1;
 CTGroupBox m_TGrpBox2;
 // …
}

Thats all!

Note: Group boxes are technically buttons(!) with style BS_GROUPBOX
but they don’t seem to receive WM_DRAWITEMs even if BS_OWNERDRAW is set. So
I do the drawing in an WM_PAINT handler but thats not too hard here because
they can’t be “pressed” or get the focus rect.

Comments, suggestions, bug reports etc. are welcome! Put them here as
comment or send them directly to me.

Enjoy!

Downloads

Download source – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.