Getting battery information of a windows CE 5.0 device

孤人 提交于 2019-12-01 10:55:23

问题


Sir, I am developing an application for a device running WINDOWS CE 5.0. I want to know the battery/power information of the device. I am quit new in CE programming. Please make clear is there any difference between windows mobile programming and CE programming? I found MICROSOFT.WINDOWSMOBILE.STATUS namespace to work with. But when i include the reference, this namespace is not visible in the list. What should i do?


回答1:


You need to P/Invoke GetSystemPowerStatusEx. An example is actually found in this old MSDN article.




回答2:


I have used the P/Invoke GetSystemPowerStatusEx before and found it caused memory leaks when calling it frequently. For reliable event driven battery status I'd go down the route of SystemState Events.

using Microsoft.WindowsMobile.Status;
_batteryState = new SystemState(SystemProperty.PowerBatteryState) { ComparisonType = StatusComparisonType.AnyChange };
_batteryState.Changed += (o, e) => UpdateBatteryIcon();

private void UpdateBatteryIcon()
{
    var batteryLevel = SystemState.PowerBatteryStrength;
    var isOnCharge = IsOnCharge(SystemState.PowerBatteryState);
    _batteryWarning = batteryLevel == BatteryLevel.VeryLow && !isOnCharge;
    pictBattery.Image = GetBatteryIcon(batteryLevel, isOnCharge);
}


来源:https://stackoverflow.com/questions/5415622/getting-battery-information-of-a-windows-ce-5-0-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!