Click here to Skip to main content
Licence 
First Posted 1 Feb 2000
Views 72,498
Bookmarked 31 times

Transparent group box

By | 1 Feb 2000 | Article
A very simple group box replacement to enhance your user interface
  • Download source files - 2 Kb
  • Sample Image - TGroupBox.gif

    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
    {
    private:
    	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.

    Enjoy!

    License

    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

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralLicense Pinmemberkishoresajja8:47 27 Apr '10  
    Generalradiobuttons inside groupbox Pinmemberkayserili8021:58 10 May '09  
    GeneralRe: radiobuttons inside groupbox Pinmemberlidah1:09 27 Aug '10  
    QuestionDoes this work? PinmemberCharlieG8:21 29 Mar '04  
    GeneralArtifact when selecting PinsussAnonymous10:40 12 May '03  
    GeneralRe: Artifact when selecting PinsussRob Morris8:04 13 Aug '04  
    GeneralFont assertion Pinsusskathy 9:57 24 Mar '00  
    GeneralIt has two bugs... PinsussByoungmin Kim22:52 9 Feb '00  
    GeneralRe: It has two bugs... PinmemberAtlantys10:29 22 Feb '02  
    GeneralRe: It has two bugs... Pinmemberlidah1:07 27 Aug '10  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
    Web03 | 2.5.120517.1 | Last Updated 2 Feb 2000
    Article Copyright 2000 by Jens Schacherl
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid