Static control using WS_EX_TRANSPARENT style not repainted
I am trying to create a control that implements an alpha blend per pixel when drawing a 32bit bitmap.
I extended CWnd and used static control in the resource editor. I managed to draw the alpha channel correctly, but still the static control keeps drawing the gray background.
I overwritten OnEraseBkgnd to prevent the background from being drawn, but it didn't work. I was finally able to do this using WS_EX_TRANSPARENT.
Now my problem is that my control is over another control. The first time the dialog is colored everything works fine ... but if I click the "parent" control (ie the one under my control), my control did not receive the WM_PAINT message. Therefore, it is no longer colored.
If I hide the app and enlarge it again, the controls are colored again.
Please can someone give a hint? I'm going crazy with this control!
Thank.
source to share
If you were handling the WM_ERASEBKGND and WM_PAINT messages , then you would have to cover all the drawing options without resorting to using WS_EX_TRANSPARENT .
Are you sure your code is not passing these messages for processing by default ?
Another option could be a static member subclass to make sure your code is the only one handling these two messages.
source to share
BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
BOOL CTransparentStatic::OnEraseBkgnd(CDC* /*pDC*/)
{
// Prevent from default background erasing.
return FALSE;
}
BOOL CTransparentStatic::PreCreateWindow(CREATESTRUCT& cs)
{
cs.dwExStyle |= WS_EX_TRANSPARENT;
return CStatic::PreCreateWindow(cs);
}
HBRUSH CTransparentStatic::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetBkMode(TRANSPARENT);
return reinterpret_cast<HBRUSH>(GetStockObject(NULL_BRUSH));
}
void CTransparentStatic::PreSubclassWindow()
{
CStatic::PreSubclassWindow();
const LONG_PTR exStyle = GetWindowLongPtr(m_hWnd, GWL_EXSTYLE);
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, exStyle | WS_EX_TRANSPARENT);
}
source to share
http://unick-soft.ru/Articles.cgi?id=12 - sorry for Russian, but there is an example. The example contains a hyperlink "To an example you can download" in the bottom article after the sample code. Learn Russian :)