【IT168技术文档】
今天在Peter Foot的博客上看到如何获取系统的电源状态(不是电池状态)的一篇文章,
他使用的VB描述:
<DllImport("coredll.dll")> _ PublicSharedFunction GetSystemPowerState(ByVal pBuffer As System.Text.StringBuilder, ByVal Length AsInteger, ByRef pFlags As PowerState) AsInteger EndFunction <Flags()> _ PublicEnum PowerState [On] = &H10000 '// on state Off= &H20000 ' // no power, full off Critical = &H40000 '// critical off Boot = &H80000 ' // boot state Idle = &H100000 ' // idle state Suspend = &H200000 ' // suspend state Unattended = &H400000 ' // Unattended state. Reset= &H800000 ' // reset state UserIdle = &H1000000 ' // user idle state BackLightOn = &H2000000 ' // device screen backlight on Password = &H10000000 ' // This state is password protected. EndEnum PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sb AsNew System.Text.StringBuilder(260) Dim flags As PowerState = 0 Dim ret AsInteger= GetSystemPowerState(sb, sb.Capacity, flags) TextBox1.Text = sb.ToString() TextBox2.Text = flags.ToString() EndSub