diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj
index f53b97e..11c7da8 100644
--- a/Correlator/Correlator.csproj
+++ b/Correlator/Correlator.csproj
@@ -264,6 +264,7 @@
+
@@ -309,7 +310,6 @@
-
diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj
index f53b97e..11c7da8 100644
--- a/Correlator/Correlator.csproj
+++ b/Correlator/Correlator.csproj
@@ -264,6 +264,7 @@
+
@@ -309,7 +310,6 @@
-
diff --git a/Correlator/Model/SystemPowerStatus.cs b/Correlator/Model/SystemPowerStatus.cs
new file mode 100644
index 0000000..a2bee25
--- /dev/null
+++ b/Correlator/Model/SystemPowerStatus.cs
@@ -0,0 +1,44 @@
+using System.Runtime.InteropServices;
+
+namespace Correlator.Model
+{
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SystemPowerStatus
+ {
+ ///
+ /// 0x00 - Offline (no AC power)
+ /// 0x01 - Online (AC power is available)
+ ///
+ public byte ACLineStatus;
+
+ ///
+ /// 0x00 - No system battery
+ /// 0x01 - High
+ /// 0x02 - Low
+ /// 0x04 - Critical
+ /// 0x08 - Charging
+ /// 0x80 - No system battery and AC power is available
+ ///
+ public byte BatteryFlag;
+
+ ///
+ /// Percentage of battery life remaining (range is 0-100)
+ ///
+ public byte BatteryLifePercent;
+
+ ///
+ /// Reserved, must be 0
+ ///
+ public byte Reserved1;
+
+ ///
+ /// Remaining battery life in seconds
+ ///
+ public int BatteryLifeTime;
+
+ ///
+ /// Estimated total battery life in seconds
+ ///
+ public int BatteryFullLifeTime;
+ }
+}
\ No newline at end of file
diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj
index f53b97e..11c7da8 100644
--- a/Correlator/Correlator.csproj
+++ b/Correlator/Correlator.csproj
@@ -264,6 +264,7 @@
+
@@ -309,7 +310,6 @@
-
diff --git a/Correlator/Model/SystemPowerStatus.cs b/Correlator/Model/SystemPowerStatus.cs
new file mode 100644
index 0000000..a2bee25
--- /dev/null
+++ b/Correlator/Model/SystemPowerStatus.cs
@@ -0,0 +1,44 @@
+using System.Runtime.InteropServices;
+
+namespace Correlator.Model
+{
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SystemPowerStatus
+ {
+ ///
+ /// 0x00 - Offline (no AC power)
+ /// 0x01 - Online (AC power is available)
+ ///
+ public byte ACLineStatus;
+
+ ///
+ /// 0x00 - No system battery
+ /// 0x01 - High
+ /// 0x02 - Low
+ /// 0x04 - Critical
+ /// 0x08 - Charging
+ /// 0x80 - No system battery and AC power is available
+ ///
+ public byte BatteryFlag;
+
+ ///
+ /// Percentage of battery life remaining (range is 0-100)
+ ///
+ public byte BatteryLifePercent;
+
+ ///
+ /// Reserved, must be 0
+ ///
+ public byte Reserved1;
+
+ ///
+ /// Remaining battery life in seconds
+ ///
+ public int BatteryLifeTime;
+
+ ///
+ /// Estimated total battery life in seconds
+ ///
+ public int BatteryFullLifeTime;
+ }
+}
\ No newline at end of file
diff --git a/Correlator/Util/SystemConfig.cs b/Correlator/Util/SystemConfig.cs
deleted file mode 100644
index 385e00b..0000000
--- a/Correlator/Util/SystemConfig.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-namespace Correlator.Util
-{
- public class SystemConfig
- {
- ///
- /// 顺序不可更改
- ///
- public struct SystemPowerStatus
- {
- public ACLineStatus AcLineStatus; //0 = offline, 1 = Online, 255 = UnKnown Status.
- public BatteryFlag BatteryFlag;
- public byte BatteryPercent;
- public SystemStatusFlag StatusFlag;
- public int BatteryLifeTime;
- public int BatteryFullLifeTime;
- }
-
- public enum ACLineStatus : byte
- {
- Offline = 0, //offline
- Online = 1, //Online
- UnKnownStatus = 255 // 未知
- }
-
- public enum BatteryFlag : byte
- {
- Middle = 0, // 电池未充电并且电池容量介于高电量和低电量之间
- High = 1, // 电池电量超过66%
- Low = 2, // 电池电量不足33%
- Critical = 4, // 电池电量不足百分之五
- Charging = 8, // 充电中
- NoSystemBattery = 128, // 无系统电池
- UnKnownStatus = 255 // 无法读取电池标志信息
- }
-
- public enum SystemStatusFlag : byte
- {
- Off = 0, // 节电功能已关闭
- On = 1 // 节电功能已打开,节省电池。尽可能节约能源
- }
- }
-}
\ No newline at end of file
diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj
index f53b97e..11c7da8 100644
--- a/Correlator/Correlator.csproj
+++ b/Correlator/Correlator.csproj
@@ -264,6 +264,7 @@
+
@@ -309,7 +310,6 @@
-
diff --git a/Correlator/Model/SystemPowerStatus.cs b/Correlator/Model/SystemPowerStatus.cs
new file mode 100644
index 0000000..a2bee25
--- /dev/null
+++ b/Correlator/Model/SystemPowerStatus.cs
@@ -0,0 +1,44 @@
+using System.Runtime.InteropServices;
+
+namespace Correlator.Model
+{
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SystemPowerStatus
+ {
+ ///
+ /// 0x00 - Offline (no AC power)
+ /// 0x01 - Online (AC power is available)
+ ///
+ public byte ACLineStatus;
+
+ ///
+ /// 0x00 - No system battery
+ /// 0x01 - High
+ /// 0x02 - Low
+ /// 0x04 - Critical
+ /// 0x08 - Charging
+ /// 0x80 - No system battery and AC power is available
+ ///
+ public byte BatteryFlag;
+
+ ///
+ /// Percentage of battery life remaining (range is 0-100)
+ ///
+ public byte BatteryLifePercent;
+
+ ///
+ /// Reserved, must be 0
+ ///
+ public byte Reserved1;
+
+ ///
+ /// Remaining battery life in seconds
+ ///
+ public int BatteryLifeTime;
+
+ ///
+ /// Estimated total battery life in seconds
+ ///
+ public int BatteryFullLifeTime;
+ }
+}
\ No newline at end of file
diff --git a/Correlator/Util/SystemConfig.cs b/Correlator/Util/SystemConfig.cs
deleted file mode 100644
index 385e00b..0000000
--- a/Correlator/Util/SystemConfig.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-namespace Correlator.Util
-{
- public class SystemConfig
- {
- ///
- /// 顺序不可更改
- ///
- public struct SystemPowerStatus
- {
- public ACLineStatus AcLineStatus; //0 = offline, 1 = Online, 255 = UnKnown Status.
- public BatteryFlag BatteryFlag;
- public byte BatteryPercent;
- public SystemStatusFlag StatusFlag;
- public int BatteryLifeTime;
- public int BatteryFullLifeTime;
- }
-
- public enum ACLineStatus : byte
- {
- Offline = 0, //offline
- Online = 1, //Online
- UnKnownStatus = 255 // 未知
- }
-
- public enum BatteryFlag : byte
- {
- Middle = 0, // 电池未充电并且电池容量介于高电量和低电量之间
- High = 1, // 电池电量超过66%
- Low = 2, // 电池电量不足33%
- Critical = 4, // 电池电量不足百分之五
- Charging = 8, // 充电中
- NoSystemBattery = 128, // 无系统电池
- UnKnownStatus = 255 // 无法读取电池标志信息
- }
-
- public enum SystemStatusFlag : byte
- {
- Off = 0, // 节电功能已关闭
- On = 1 // 节电功能已打开,节省电池。尽可能节约能源
- }
- }
-}
\ No newline at end of file
diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs
index 39b278f..d6866b0 100644
--- a/Correlator/ViewModels/MainWindowViewModel.cs
+++ b/Correlator/ViewModels/MainWindowViewModel.cs
@@ -484,8 +484,8 @@
#region PC电量状态
- [DllImport("kernel32.dll", EntryPoint = "GetSystemPowerStatus")]
- private static extern void GetSystemPowerStatus(ref SystemConfig.SystemPowerStatus lpSystemPowerStatus);
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern void GetSystemPowerStatus(ref SystemPowerStatus lpSystemPowerStatus);
#endregion
@@ -1043,14 +1043,14 @@
_timer.Start();
//获取电池电量
- var sysPower = new SystemConfig.SystemPowerStatus();
+ var sysPower = new SystemPowerStatus();
GetSystemPowerStatus(ref sysPower);
- ComputerBattery = sysPower.BatteryPercent == 255 ? 100 : sysPower.BatteryPercent;
+ ComputerBattery = sysPower.BatteryLifePercent;
_batteryTimer.Tick += delegate
{
GetSystemPowerStatus(ref sysPower);
- ComputerBattery = sysPower.BatteryPercent == 255 ? 100 : sysPower.BatteryPercent;
+ ComputerBattery = sysPower.BatteryLifePercent;
};
_batteryTimer.Start();