Win32 C++ SetLayeredWindowAttributes is either fully opaque or fully transparent; nothing in between

好久不见. 提交于 2021-02-07 10:20:57

问题


So I have a 2nd Window created within my program like:

#define WINDOW_CLASS_NAME "WINCLASSFULL"

WNDCLASSEX winclass;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

some function {

HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

// first fill in the window class stucture

winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style          = CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc    =WndProc;
winclass.cbClsExtra = 0;                        //reserve data space
winclass.cbWndExtra = 0;                        //
winclass.hInstance  = hInstance;                //set instance of application
winclass.hIcon      = NULL;
winclass.hCursor    = LoadCursor(NULL, IDC_ARROW);         //load cursor type
winclass.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH); //set background brush
winclass.lpszMenuName   = NULL;                               
winclass.lpszClassName  = WINDOW_CLASS_NAME;                 //set Windows class name
winclass.hIconSm        = NULL;

hWnd= CreateWindowEx(WS_EX_LAYERED,                  // extended style
                            WINDOW_CLASS_NAME,     // class
                            "Demo", // title
                            WS_POPUP,
                            x,y,
                            width,height,
                            NULL,
                            NULL, 
                            hInstance,// instance of this application
                            NULL))) // extra creation parms

}

Now my issue is if I apply

Where 255 can be anything between 1-255

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),255,LWA_COLORKEY|LWA_ALPHA)

The window is fully opaque i can't see anything behind it

This is fully transparent:

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),0,LWA_COLORKEY|LWA_ALPHA)

How can I get

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),128,LWA_COLORKEY|LWA_ALPHA)

To work - i.e. so I can partially see my window on top; and partially see window behind it. I've checked the doco on MSDN here but I'm obviously missing something Refer Microsoft Library


回答1:


Try to specify only LWA_ALPHA, not both LWA_COLORKEY and LWA_ALPHA



来源:https://stackoverflow.com/questions/8787753/win32-c-setlayeredwindowattributes-is-either-fully-opaque-or-fully-transparent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!