码迷,mamicode.com
首页 > 其他好文 > 详细

C#:获取设备电量相关信息

时间:2014-07-01 19:39:50      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   line   new   div   

  [DllImport("kernel32.dll",EntryPoint="GetSystemPowerStatus")]   //win32 api
        private static extern void GetSystemPowerStatus(ref SYSTEM_POWER_STATUS lpSystemPowerStatus);   

         public struct SYSTEM_POWER_STATUS    //结构体
         {   
             public Byte ACLineStatus;                //0 = offline, 1 = Online, 255 = UnKnown Status.   
             public Byte BatteryFlag;   
            public Byte BatteryLifePercent;   
            public Byte Reserved1;   
            public int BatteryLifeTime;   
             public int BatteryFullLifeTime;   
         }  

        /// <summary>
        ///  获取系统电量百分比
        /// </summary>
        /// <returns></returns>
        public static float GetSystemPower()
        {
            SYSTEM_POWER_STATUS SysPower = new SYSTEM_POWER_STATUS();
            GetSystemPowerStatus(ref SysPower);

            return SysPower.BatteryLifePercent;
        }

 

C#:获取设备电量相关信息,布布扣,bubuko.com

C#:获取设备电量相关信息

标签:style   blog   color   line   new   div   

原文地址:http://www.cnblogs.com/denghejun/p/3817041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!