Transparent Group Box Control

reposts:http://www.codeguru.com/cpp/controls/controls/groupbox/article.php/c2273/Transparent-Group-Box-Control.htm


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:

 
 
  1. // in your .cpp file
  2. void CMyBitmappedDialog::OnInitDialog()
  3. {
  4. // I'm using Joerg Koenigs CBitmapDialog class
  5. // (see Dialog section of CodeGuru for more info)
  6. CBitmapDialog::OnInitDialog();
  7.  
  8. m_TGrpBox1.SubclassDlgItem(IDC_GRPBOX1, this);
  9. m_TGrpBox2.SubclassDlgItem(IDC_GRPBOX2, this);
  10. //...
  11. return TRUE;
  12. }
 
 
  1. // in your .h file
  2. #include "TGroupBox.h"
  3.  
  4. class CMyBitmappedDialog : public CBitmapDialog
  5. {
  6. private:
  7. CTGroupBox m_TGrpBox1;
  8. CTGroupBox m_TGrpBox2;
  9. // ...
  10. }

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值