C++ 子窗口透明性问题

C++ 子窗口透明性问题,c++,winapi,C++,Winapi,我正在尝试创建一个子窗口,其中的透明区域由位图中的RGB(0、0、255)识别,该位图将绘制在整个子窗口中 下面是我用来使其透明的代码,问题是子窗口透明部分下面的父窗口也变得透明,桌面通过它可见 hwndChild = ::CreateWindowEx ( 0, "mycustomwindow", txt.c_str ( ), WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD, x, y, width, height, parent, 0, hInsta

我正在尝试创建一个子窗口,其中的透明区域由位图中的RGB(0、0、255)识别,该位图将绘制在整个子窗口中

下面是我用来使其透明的代码,问题是子窗口透明部分下面的父窗口也变得透明,桌面通过它可见

hwndChild = ::CreateWindowEx ( 0, "mycustomwindow", txt.c_str (  ), WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD, x, y, width, height, parent, 0, hInstance, ( LPVOID ) this ) ;

transparent (  );



void transparent (  )
{



    HMODULE hUser32 = GetModuleHandle (  ( "USER32.DLL" )  );



    COLORREF g_ColourKey    = 0xFF00FF;     // 0,0,255(magenta) in RGB hex value


    typedef BOOL ( WINAPI *lpfnSetLayeredWindowAttributes ) ( HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags );
    lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;

    SetLayeredWindowAttributes = ( lpfnSetLayeredWindowAttributes ) GetProcAddress ( hUser32, "SetLayeredWindowAttributes" );

    if( SetLayeredWindowAttributes == NULL ) 
    {


        MessageBox ( hwndChild, "Error, cannot load window transparency\n REASON: Could not load User32.DLL", "Error!", MB_ICONSTOP | MB_OK );


    }
    else
    { 


        DWORD dwStyle = GetWindowLong ( hwndChild, GWL_STYLE ); 

        dwStyle &= ~( WS_CAPTION | WS_SIZEBOX ); 

        SetWindowLong  ( hwndChild, GWL_STYLE, dwStyle );


        InvalidateRect ( hwndChild, NULL, true ); 

        SetWindowPos   ( hwndChild, NULL, 0, 0, wWidth, wHeight, SWP_NOMOVE | SWP_NOZORDER );


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

        SetLayeredWindowAttributes ( hwndChild, g_ColourKey, 0, LWA_COLORKEY );


    }



};

父窗口(位于顶层窗口)本身使用相同的功能使某些部分透明,具有以下dwStyle:WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN

什么操作系统版本?直到windows 8 afaik,子窗口才支持分层。@JonathanPotter windows 7。。。还有其他方法吗?将子窗口渲染为内存位图,然后以透明的方式将其显示到主窗口。@JonathanPotter如果我们需要子窗口中的鼠标事件,并且子窗口中还有更多子窗口,该怎么办?然后会变得复杂:)