문제

I am trying to create a simple transparent window where I can draw with Direct2D.

So far what I have done:

  1. Created window
  2. Set style to WS_EX_LAYERED
  3. Set alpha color key as #FFF
  4. Draw using Windows Graphics a white rectangle
  5. Now window is transparent with per-pixel alpha
  6. Then make a target out of the window and draw using Direct2D
    • Make ALPHA _PREMULIPLIED target
    • Clear with #FFF with 0.0f alpha
  7. Window is now black

I just don't know how to make window to transparent. If you can point out my mistake, I would be obliged

도움이 되었습니까?

해결책 2

I don't think it's possible with directX. However GDI does work.

Take a look at the source here to see how it's done: http://pastebin.com/NJf8wi2V

In the source you can see that there is an option to attempt to use directx/opengl. However as you can see from running they do not work.

다른 팁

Here how it's achievable using DirectComposition API

Russian: http://www.oszone.net/25395/

English: https://msdn.microsoft.com/magazine/dn745861.aspx

Basically what author does is

  1. Sets WS_EX_NOREDIRECTIONBITMAP extended style to remove redirection bitmap of DWM. Content of window is now empty.

  2. Creates DirectComposition device

  3. Creates Composition SwapChain (and not hwnd swapchain)

  4. Places one visual with SwapChain as content as root visual.

  5. Renders into SwapChain using Direct2D API.

It also works well with WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST for creating event-transparent overlays.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top