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