笔记本电池电量显示
```#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$INIFile = @ScriptDir & "\Options.ini"
If FileExists($INIFile) = 0 Then IniWrite($INIFile, "UIOptions", "Refresh Rate", "500")
$RefreshRate = IniRead($INIFile, "UIOptions", "Refresh Rate", "500")
Opt("GUIOnEventMode", 1)
Global $BatteryPercent = "Please Wait... "
Global $BatteryStatus = "Please Wait... "
$FormWidth = 410
$FormHeight = 100
$Form1 = GUICreate("笔记本电量 显示示例 v.0.1", 386, 17, @DesktopWidth - $FormWidth, @DesktopHeight - $FormHeight);width height left top
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
GUISetBkColor(0xC0C0C0)
$Progress1 = GUICtrlCreateProgress(0, 0, 358, 17, BitOR($PBS_SMOOTH, $WS_BORDER))
GUICtrlSetColor(-1, 0x0000FF)
$Progress1context = GUICtrlCreateContextMenu($Progress1)
$PMenuItem1 = GUICtrlCreateMenuItem("Options", $Progress1context)
GUICtrlSetOnEvent($PMenuItem1, "OptionsWindow")
$PMenuItem2 = GUICtrlCreateMenu("Close...", $Progress1context)
$PMenuItem3 = GUICtrlCreateMenuItem("...To Tray", $PMenuItem2)
$PMenuItem4 = GUICtrlCreateMenuItem("...And Exit", $PMenuItem2)
GUICtrlSetOnEvent($PMenuItem4, "ExitApp")
$Label1 = GUICtrlCreateLabel("", 358, 0, 28, 17, $WS_BORDER);left top width height
$Label1context = GUICtrlCreateContextMenu($Label1)
$MenuItem1 = GUICtrlCreateMenuItem("Options", $Label1context)
$MenuItem2 = GUICtrlCreateMenu("Close...", $Label1context)
$MenuItem3 = GUICtrlCreateMenuItem("...To Tray", $MenuItem2)
$MenuItem4 = GUICtrlCreateMenuItem("...And Exit", $MenuItem2)
GUICtrlSetOnEvent($MenuItem4, "ExitApp")
GUISetState(@SW_SHOW)
While 1
$SYSTEM_POWER_STATUS = DllStructCreate("byte;byte;byte;byte;int;int")
$test = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", _
"ptr", DllStructGetPtr($SYSTEM_POWER_STATUS))
$BatteryStatus = DllStructGetData($SYSTEM_POWER_STATUS, 1)
If $BatteryStatus = "1" Then $BatteryStatus = "Charging"
If $BatteryStatus = "0" Then $BatteryStatus = "Discharging"
$BatteryPercent = DllStructGetData($SYSTEM_POWER_STATUS, 3)
GUICtrlSetData($Progress1, $BatteryPercent)
GUICtrlSetData($Label1, $BatteryPercent & "%")
Sleep($RefreshRate)
WEnd
Func ExitApp()
Exit
EndFunc ;==>ExitApp
Func OptionsWindow()
;going to do this later
EndFunc ;==>OptionsWindow```
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!