Click here to Skip to main content
13,143,774 members (37,866 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 1 Feb 2000

Transparent group box

, 1 Feb 2000
Rate this:
Please Sign up or sign in to vote.
A very simple group box replacement to enhance your user interface
  • Download source files - 2 Kb
  • Sample Image - TGroupBox.gif

    <!-- Article Starts -->

    If you make a dialog with a bitmap as background, you'll probably handle WM_CTLCOLOR and 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()
    	CBitmapDialog::OnInitDialog();  // I'm using Joerg Koenigs CBitmapDialog class
    	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
    	CTGroupBox m_TGrpBox1;
    	CTGroupBox m_TGrpBox2;

    Thats all!

    Remark: Group boxes are technically buttons(!) with style BS_GROUPBOX but they don't seem to receive WM_DRAWITEM messages 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.



    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Jens Schacherl
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Questionlicense terms? Pin
    Sander rawat18-May-17 19:02
    memberSander rawat18-May-17 19:02 
    AnswerRe: license terms? Pin
    SoMad18-May-17 19:29
    protectorSoMad18-May-17 19:29 
    GeneralLicense Pin
    kishoresajja27-Apr-10 8:47
    memberkishoresajja27-Apr-10 8:47 
    Generalradiobuttons inside groupbox Pin
    kayserili8010-May-09 21:58
    memberkayserili8010-May-09 21:58 
    GeneralRe: radiobuttons inside groupbox Pin
    lidah27-Aug-10 1:09
    memberlidah27-Aug-10 1:09 
    QuestionDoes this work? Pin
    CharlieG29-Mar-04 8:21
    memberCharlieG29-Mar-04 8:21 
    GeneralArtifact when selecting Pin
    Anonymous12-May-03 10:40
    sussAnonymous12-May-03 10:40 
    GeneralRe: Artifact when selecting Pin
    Rob Morris13-Aug-04 8:04
    sussRob Morris13-Aug-04 8:04 
    GeneralFont assertion Pin
    kathy 24-Mar-00 9:57
    susskathy 24-Mar-00 9:57 
    GeneralIt has two bugs... Pin
    Byoungmin Kim9-Feb-00 22:52
    sussByoungmin Kim9-Feb-00 22:52 
    GeneralRe: It has two bugs... Pin
    Atlantys22-Feb-02 10:29
    memberAtlantys22-Feb-02 10:29 
    GeneralRe: It has two bugs... Pin
    lidah27-Aug-10 1:07
    memberlidah27-Aug-10 1:07 
    GeneralRe: It has two bugs... Pin
    Dave Foster17-Mar-16 11:06
    memberDave Foster17-Mar-16 11:06 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.170915.1 | Last Updated 2 Feb 2000
    Article Copyright 2000 by Jens Schacherl
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid