Download source files - 2 Kb
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
:
void CMyBitmappedDialog::OnInitDialog()
{
CBitmapDialog::OnInitDialog();
m_TGrpBox1.SubclassDlgItem(IDC_GRPBOX1, this);
m_TGrpBox2.SubclassDlgItem(IDC_GRPBOX2, this);
...
return TRUE;
}
#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!
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.