none
获取WinCE设备电量的奇怪问题 RRS feed

  • 问题

  • Imports System.Runtime.InteropServices
    
    Public Class Form1
      <StructLayout(LayoutKind.Auto)> _
      Public Class SYSTEM_POWER_STATUS_EX2
        Public ACLineStatus As Byte
        Public BatteryFlag As Byte
        Public BatteryLifePercent As Byte
        Public Reserved1 As Byte
        Public BatteryLifeTime As Int16
        Public BatteryFullLifeTime As Int16
        Public Reserved2 As Byte
        Public BatteryBackupFlag As Byte
        Public BackupBatteryLifeTime As Byte ' DocBug
        Public Reserved3 As Byte
        Public BackupBatteryLifePercent As Byte 'DocBug
        Public BackupBatteryFullLifeTime As Byte
      End Class
    
      Declare Function GetSystemPowerStatusEx2 Lib "coredll.dll" (<Out()> ByRef pStatus As SYSTEM_POWER_STATUS_EX2, ByVal fUpdate As Boolean) As Boolean
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sps As New SYSTEM_POWER_STATUS_EX2
        Dim ret As Boolean = GetSystemPowerStatusEx2(sps, True)
        TextBox1.Text = sps.BatteryLifePercent.ToString
      End Sub
    End Class
    

    第一次点Button1的时候可以获取,但是也不准确,例如当前电量49%,获取的是45%

    再点下就成26%,不知道什么原因,搞不懂。网上的那些都是C#的,我用VB重写一次也是老有问题,哪位大侠帮帮忙啊,

     

    另外,还有个小问题,如何获取WinCE移动设备网卡的MAC地址,


    欢迎到我的博客一起讨论 http://www.raymanzhai.com
    2010年12月29日 11:32

答案