注意:

在调用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;
    }
}

 

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-26
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2023-03-09
  • 2022-12-23
  • 2021-10-04
  • 2021-12-28
  • 2021-12-04
  • 2021-08-29
  • 2021-12-04
相关资源
相似解决方案