1

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

#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

}

现在我的问题是如果我申请

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

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

窗户完全不透明,我看不到它后面的任何东西

这是完全透明的:

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 Library

4

1 回答 1

3

尝试仅指定LWA_ALPHA,不同时指定LWA_COLORKEYLWA_ALPHA

于 2012-01-09T11:36:39.093 回答