/// <summary> /// 设置窗口透明度 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="alpha">透明度</param> public static void SetWindowAlpha(IntPtr hWnd, byte alpha) { //在调用SetLayeredWindowAttributes 之前,需要给窗口加上WS_EX_LAYERED属性,否则会无效 var wndExStyle = Win32Funcs.GetWindowLongWrapper(hWnd, Win32Consts.GWL_EXSTYLE); wndExStyle |= Win32Consts.WS_EX_LAYERED; Win32Funcs.SetWindowLongWrapper(hWnd, Win32Consts.GWL_EXSTYLE, wndExStyle); //设置透明度 Win32Funcs.SetLayeredWindowAttributesWrapper(hWnd, 0, alpha, Win32Consts.LWA_ALPHA); }