0

I have a window on which I call DwmExtendFrameIntoClientArea(), the window hosts other child windows, I use Direct2D to paint on one of the child windows, When a bitmap is loaded which has a black region on it, that region becomes blurred. I wish to clear everything in the child window and paint it again on WM_PAINT, however I cannot seem to clear the contents.

  1. I have tried to clear it using

    m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::Black))
    

    This makes the child window region black, it erases all previous drawing, but no transparency.

  2. I have tried to draw a bitmap which is just a black bar over the client area

    m_pRenderTarget->DrawBitmap(m_pBkgrnd,D2D1::Rect<float> (0.f,0.f,GetWidth(),GetHeight()))
    

    This makes whatever that had appeared before it, in black.

  3. Tried the old GDI way of painting a black region over the entire child window,

    RECT rc;
    GetClientRect(m_hwnd, &rc);
    HBRUSH brush = CreateSolidBrush(RGB(0,0,0));
    HDC hc=GetDC(m_hwnd);
    FillRect(hc, &rc, brush);
    ReleaseDC(m_hwnd,hc);
    DeleteObject(brush);
    

    Doesn't work.

  4. However if I don't do any of this and I try to resize the main window, it works right i.e. the previous painting dissappears.

Is there any API call or any way to clear the window manually before I draw it again?

Michael
  • 8,920
  • 3
  • 38
  • 56
Prasanth Ravi
  • 145
  • 1
  • 11

1 Answers1

0

How are you initializing your render target? Make sure you specify Premultipled Alpha, and not Straight or Ignore. Then, to clear everything to transparent, use ID2D1RenderTarget::Clear(D2D1::ColorF(0, 0, 0, 0)). You cannot use something like FillRectangle to draw with a transparent color, as that will blend the transparent color into what's already there and that is a no-op.

Rick Brewster
  • 3,374
  • 1
  • 17
  • 21