How do I clear a Direct2D render target to fully transparent

前端 未结 3 1284
梦毁少年i
梦毁少年i 2020-12-11 05:06

I\'m trying to draw semi-transparent rectangles on an invisible HWND. However, clearing the window with ID2D1HwndRenderTarget::Clear just makes the entire w

3条回答
  •  执笔经年
    2020-12-11 05:46

    Use ID2D1DCRendTarget instead of ID2D1HwndRendTarget, then bind the device context (DC) of your window before drawing begins.

    Of course, you need to set the WS_EX_LAYERED for your window and then call SetLayeredWindowAttributes to set the transparent color:

    SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
    

    Screenshot:

提交回复
热议问题