Transparent checkbox text?
-
Hi, I need to know how to draw the checkbox button text background transparent. Thanks
-
Hi, I need to know how to draw the checkbox button text background transparent. Thanks
You could try the usual tricks - the WS_EX_TRANSPARENT flag, handling WM_ERASEBKGND, etc. but I suspect they won't work on checkboxes. You can always render the text yourself :)
-
You could try the usual tricks - the WS_EX_TRANSPARENT flag, handling WM_ERASEBKGND, etc. but I suspect they won't work on checkboxes. You can always render the text yourself :)
Hi, I have tried to handle WM_ERASEBKGND and I have also set WS_EX_TRANSPARENT for my CButton derived control, but the background still is not transparent. How can I render the text only? I don't want to draw the box and the checkmark myself. Thanks
-
Hi, I have tried to handle WM_ERASEBKGND and I have also set WS_EX_TRANSPARENT for my CButton derived control, but the background still is not transparent. How can I render the text only? I don't want to draw the box and the checkmark myself. Thanks
Yeah... most, if not all, of the standard controls use opaque background on their text. You can draw it yourself using something like DrawText(). Obtain the checkbox rect in OnInitDialog() and set the controls text to an empty string (you could get the text first so you have the text string). In OnPaint(), call the base class OnPaint() then get a DC for the window and select a pen of the text color into it, set its background mode to transparent, and use DrawText() to render the string. The Microsoft recommended method is owner draw. Mark
-
Hi, I need to know how to draw the checkbox button text background transparent. Thanks
Did you try it with ON_WM_CTLCOLOR_REFLECT ? for my purposes, it worked...
class CTransparentCheckbox : public CButton { public: CTransparentCheckbox(); //{{AFX_VIRTUAL(CTransparentCheckbox) //}}AFX_VIRTUAL virtual ~CTransparentCheckbox(); protected: //{{AFX_MSG(CButtonEx) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////////////////////////// // CTransparentCheckbox CTransparentCheckbox::CTransparentCheckbox() { } CTransparentCheckbox::~CTransparentCheckbox() { } BEGIN_MESSAGE_MAP(CTransparentCheckbox, CButton) //{{AFX_MSG_MAP(CTransparentCheckbox) ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP END_MESSAGE_MAP() // Handler for WM_CTLCOLOR reflected message (see message map) HBRUSH CTransparentCheckbox::CtlColor(CDC* pDC, UINT nCtlColor) { ASSERT(nCtlColor == CTLCOLOR_STATIC); // Set transparent drawing mode pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); }
greetings, ralf. -
Did you try it with ON_WM_CTLCOLOR_REFLECT ? for my purposes, it worked...
class CTransparentCheckbox : public CButton { public: CTransparentCheckbox(); //{{AFX_VIRTUAL(CTransparentCheckbox) //}}AFX_VIRTUAL virtual ~CTransparentCheckbox(); protected: //{{AFX_MSG(CButtonEx) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////////////////////////// // CTransparentCheckbox CTransparentCheckbox::CTransparentCheckbox() { } CTransparentCheckbox::~CTransparentCheckbox() { } BEGIN_MESSAGE_MAP(CTransparentCheckbox, CButton) //{{AFX_MSG_MAP(CTransparentCheckbox) ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP END_MESSAGE_MAP() // Handler for WM_CTLCOLOR reflected message (see message map) HBRUSH CTransparentCheckbox::CtlColor(CDC* pDC, UINT nCtlColor) { ASSERT(nCtlColor == CTLCOLOR_STATIC); // Set transparent drawing mode pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); }
greetings, ralf.Hi Ralf, your tip works perfectly for me! Thank you very much !!! Greetings