-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSystemAnimationHelper.cs
More file actions
93 lines (82 loc) · 3.06 KB
/
SystemAnimationHelper.cs
File metadata and controls
93 lines (82 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Runtime.InteropServices;
namespace TrayChrome
{
/// <summary>
/// 系统动画设置检测帮助类
/// </summary>
public static class SystemAnimationHelper
{
// Win32 API 常量
private const int SPI_GETCLIENTAREAANIMATION = 0x1042;
private const int SPI_GETANIMATION = 0x0048;
// Win32 API 声明
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SystemParametersInfoW(
uint uiAction,
uint uiParam,
ref bool pvParam,
uint fWinIni);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SystemParametersInfoW(
uint uiAction,
uint uiParam,
ref ANIMATIONINFO pvParam,
uint fWinIni);
[StructLayout(LayoutKind.Sequential)]
private struct ANIMATIONINFO
{
public uint cbSize;
public int iMinAnimate;
}
/// <summary>
/// 检测系统是否启用了动画效果
/// </summary>
/// <returns>true表示启用动画,false表示禁用动画</returns>
public static bool IsSystemAnimationEnabled()
{
try
{
// 方法1:检查客户区动画设置 (Windows Vista+)
bool clientAreaAnimation = true;
if (SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION, 0, ref clientAreaAnimation, 0))
{
if (!clientAreaAnimation)
return false;
}
// 方法2:检查窗口动画设置 (Windows 2000+)
ANIMATIONINFO animInfo = new ANIMATIONINFO();
animInfo.cbSize = (uint)Marshal.SizeOf(animInfo);
if (SystemParametersInfoW(SPI_GETANIMATION, animInfo.cbSize, ref animInfo, 0))
{
// iMinAnimate为0表示禁用动画
return animInfo.iMinAnimate != 0;
}
// 如果API调用失败,默认启用动画
return true;
}
catch
{
// 出现异常时默认启用动画
return true;
}
}
/// <summary>
/// 检测是否应该禁用动画
/// 综合考虑系统设置和用户偏好
/// </summary>
/// <param name="userPreference">用户在应用中的动画偏好设置</param>
/// <returns>true表示应该禁用动画</returns>
public static bool ShouldDisableAnimation(bool userPreference)
{
// 如果用户明确禁用了动画,则禁用
if (!userPreference)
return true;
// 如果系统禁用了动画,则禁用
if (!IsSystemAnimationEnabled())
return true;
// 否则启用动画
return false;
}
}
}