Static control with WS_EX_TRANSPARENT style not repainted

不想你离开。 提交于 2019-12-08 10:00:55

问题


I am trying to create a control that implements the per-pixel alpha blend while painting a 32-bit bitmap.

I extended a CWnd and use static control in the resource editor. I managed to paint the alpha channel correctly but still the static control keep painting the gray background.

I overwrote the OnEraseBkgnd to prevent the control from painting the background but it didn't worked. I finally managed to do it by using WS_EX_TRANSPARENT.

My problem now is that my control is placed over other control. The first time the dialog is painted all works fine...but if I click over the "parent" control (ie the one beneath my control) my control doesn't received the WM_PAINT message. So it is not painted anymore.

If I minimize the aplication and maximized it again the controls are painted again.

Please, can anybody give a hint? I am getting crazy with this control!!!

Thanks.


回答1:


I would have though that if you are processing both the WM_ERASEBKGND and the WM_PAINT messages then you should have cover all the painting options, without having to resort to using the WS_EX_TRANSPARENT style.

Are you sure your code is not passing these messages on to the default processing?

One other option might be to subclass the static control, just to make sure your code is the only one handling these two messages.




回答2:


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);
}



回答3:


http://unick-soft.ru/Articles.cgi?id=12 - sorry on Russian, but have Example. Example have hyper link "В примере, который вы можете скачать", on bottom article after code sample. Learn Russian :)



来源:https://stackoverflow.com/questions/319393/static-control-with-ws-ex-transparent-style-not-repainted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!