本文介绍了Win32 C++ SetLayeredWindowAttributes 要么完全不透明,要么完全透明;中间没有任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的程序中创建了第二个窗口,例如:

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

其中 255 可以是 1-255 之间的任何值

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

这是完全透明的:

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

我如何获得

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

工作 - 即我可以部分看到顶部的窗口;并部分地看到它后面的窗户.我在这里检查了 MSDN 上的 doco,但我显然错过了一些东西 参考 Microsoft 库

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

推荐答案

尽量只指定 LWA_ALPHA, 不要同时指定 LWA_COLORKEYLWA_ALPHA

Try to specify only LWA_ALPHA, not both LWA_COLORKEY and LWA_ALPHA

这篇关于Win32 C++ SetLayeredWindowAttributes 要么完全不透明,要么完全透明;中间没有任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:46