Creating a transparent window in C++ Win32

前端 未结 2 1940
我寻月下人不归
我寻月下人不归 2020-11-29 16:40

I\'m creating what should be a very simple Win32 C++ app whose sole purpose it to ONLY display a semi-transparent PNG. The window shouldn\'t have any chrome, and all the opa

2条回答
  •  死守一世寂寞
    2020-11-29 17:14

    Use the SetLayeredWindowAttributesarchive function, this allows you to set a mask color that will become transparent, thus allowing the background to show through.

    You will also need to configure your window with the layered flag, e.g.:

    SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    

    After that it's fairly simple:

    // Make red pixels transparent:
    SetLayeredWindowAttributes(hwnd, RGB(255,0,0), 0, LWA_COLORKEY);
    

    When your PNG contains semi-transparent pixels that you want to blend with the background, this becomes more complicated. You could try looking at the approach in this CodeProject article:

    Cool, Semi-transparent and Shaped Dialogs with Standard Controls for Windows 2000 and Above

提交回复
热议问题