Another transparent question
-
This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this:
CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT);
But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
-
This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this:
CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT);
But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
Control with WS_EX_TRANSPARENT has the background of its parent. You probably put static control on i.e tab control which lies on dialog. But the parent of static control is still this dialog. To correct such situation override CDialog::OnCtlColor. Type ON_WM_CTLCOLOR() in MESSAGE_MAP. Then change the background color of your static control as you wish (i.e set it as those tab control): HBRUSH CTTSDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() != IDC_DEFAULT_CHECK) { CWnd *TabCtrl = GetDlgItem(IDC_LANG_TAB); CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); TabCtrl->ScreenToClient(&Rect); COLORREF Clr = TabCtrl->GetDC()->GetPixel(Rect.left-1, Rect.top-1); DeleteObject(hbr); hbr = CreateSolidBrush(Clr); pDC->SetBkColor(Clr); } } return hbr; }
-
This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this:
CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT);
But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
MSDN: WS_EX_TRANSPARENT Specifies that a window created with this style is to be transparent. That is, any windows that are beneath the window are not obscured by the window. A window created with this style receives WM_PAINT messages only after all sibling windows beneath it have been updated. In other words all WS_EX_TRANSPARENT does is changes the way WM_PAINT is sent. To make static transparent You need to override OnCtlColor and set correct dc mode.
HBRUSH CMyFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { if (m_nWhich==ID_MY_STATIC ) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); } }