Win32 设置窗口透明度 SetLayerTransparent


注意:

在调用SetLayeredWindowAttributes 之前,需要给窗口加上WS_EX_LAYERED属性,否则会无效

void SetLayerTransparent(HWND hWnd)
{
    static bool isTransParent = false;
    if (isTransParent == false)
    {
        DWORD exStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
        exStyle |= WS_EX_LAYERED;
        ::SetWindowLong(hWnd, GWL_EXSTYLE, exStyle);
        ::SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 128, LWA_ALPHA);
        isTransParent = true;
    }
    else
    {
        ::SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 255, LWA_ALPHA);
        isTransParent = false;
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM