How to make transparent Text-Labels in CDialog ?
-
I Load and draw Picture in OnEraseBkgnd(CDC* pDC), I than need label to not overdraw background, and do
HBRUSH cWaitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkMode(TRANSPARENT); return hbr; }
Why backgound is overdrawn? thanks you. -
I Load and draw Picture in OnEraseBkgnd(CDC* pDC), I than need label to not overdraw background, and do
HBRUSH cWaitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkMode(TRANSPARENT); return hbr; }
Why backgound is overdrawn? thanks you. -
Beter if you explain ... Code that work: hbr = NULL; { if( CTLCOLOR_STATIC == nCtlColor ) { hbr = (HBRUSH)GetStockObject( HOLLOW_BRUSH ); pDC->SetBkMode( TRANSPARENT ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } thanks you for response.
-
if you dont like using 'stock objects', try using this :-D It should work LOGBRUSH lb; lb.lbStyle = BS_HOLLOW; CreateBrushIndirect(&lb);
Problem with non-stock object approach is that you may inadvertently leak GDI objects, unless you track them in the parent CDialog. Another approach would be to derive from CStatic, use message reflection so that the object handles it's own WM_CTLCOLORSTATIC, and returns a singleton hollow brush. The stock object null/hollow brush could be used there too, and you'd use control variables to associated dialog members to the appropriate control(s). Steve S