Creating a Transparent Child window on top of non-transparent Parent Window (win32)

前端 未结 3 770
终归单人心
终归单人心 2021-01-03 14:00

I have a program which is not written by me. I dont have its source and the developer of that program is developing independently. He gives me the HWND and

3条回答
  •  一向
    一向 (楼主)
    2021-01-03 14:22

    OK friends, finally I did some crazy things to make it happen. but its not very efficient, like using DirectX directly for drawing.

    What I dis:

    • Used (WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_ TOOLWINDOW) and () on CreateWindowEx
    • After creating the window, removed (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE) from window styles, and also removed (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_APPWINDOW) from extended window styles.
    • This gives me a window with no borders and its also now shown in the taskbar. also the hittest is passed to whatever that is behind my window.
    • Subclassed the window procedure of the other window and got the
      • WM_CLOSE,WM_DESTROY, to send the WM_CLOSE or WM_DESTROY respectively to my window
      • WM_SIZE,WM_MOVE, to resize and move my window according to the other window
      • WM_LBUTTONUP,WM_RBUTTONUP,WM_MBUTTONUP, to make my window brought to the top, and still keep focus on the other window, so that my window doesn't get hidden behind the other window
    • Made the DirectX device have two passes:
      • In the first pass it draws all the elements in black on top of a white background and copy the backbuffer data to an another surface (so it give a binary image of black & white).
      • In the second pass it draws the things normally.
    • Another thread is created to keep making the window transparency by reading that black & white surface, using the SetWindowRgn() function.

    This is working perfectly, the only thing is it's not very good at making things transparent.

    And the other issue is giving alpha blending to the drawn objects.

    But you can easily set the total alpha (transparency) using the SetLayeredWindowAttributes() function.

    Thanks for all the help you guys gave, all the things you guys told me was used and they guided me, as you can see. :)

    The sad thing is we decided not to use this method because of efficiency problems :(

    But I learned a lot of things, and it was an awesome experience. And that's all that matters to me :)

    Thank You :)

提交回复
热议问题