using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace AZKI
{
public partial class MainForm : Form
{
// p/invoke signature
[DllImport("coredll.dll", EntryPoint = "GetSystemPowerStatusEx2", SetLastError = true)]
public extern static Int32 GetSystemPowerStatus(
ref PowerStatus powerStatus,
Int32 length,
Boolean update);
// SYSTEM_POWER_STATUS_EX2.ACLineStatus
public enum ACLineStatus : byte
{
Offline = 0,
Online = 1,
Unknown = 255,
}
// managed version of the SYSTEM_POWER_STATUS_EX2 structure
public struct PowerStatus
{
public ACLineStatus ACLineState;
public Byte BatteryFlag;
public Byte BatteryLifePercent;
public Byte Reserved1;
public Int32 BatteryLifeTime;
public Int32 BatteryFullLifeTime;
public Byte Reserved2;
public Byte BackupBatteryFlag;
public Byte BackupBatteryLifePercent;
public Byte Reserved3;
public Int32 BackupBatteryLifeTime;
public Int32 BackupBatteryFullLifeTime;
public Int32 BatteryVoltage;
public Int32 BatteryCurrent;
public Int32 BatteryAverageCurrent;
public Int32 BatteryAverageInterval;
public Int32 BatterymAHourConsumed;
public Int32 BatteryTemperature;
public Int32 BackupBatteryVoltage;
public Byte BatteryChemistry;
}
private void button1_Click(object sender, EventArgs e)
{
PowerStatus myPowerStatus = new PowerStatus();
// query the device's power status
Int32 result = GetSystemPowerStatus(ref myPowerStatus,
Marshal.SizeOf(myPowerStatus),
true);
if (!result.Equals(0))
{
MessageBox.Show("Ac Line: " +
myPowerStatus.ACLineState.ToString());
MessageBox.Show("Remain: " +
myPowerStatus.BatteryLifePercent + "%");
}
}
}
}
구조체 정보 등은 아래를 참조.
참조: Windows CE .NET SDK documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefsystem_power_status_ex2.asp)
'Computer > .NET Compact Framework' 카테고리의 다른 글
Sound Play Class (0) | 2006.09.13 |
---|