TSystemPowerStatus
GetSystemPowerStatus
BatteryLifeTime
BatteryLifePercent
BatteryFlag
to do odczytu baterii lapka, na MSDN wszystko
kiedyś w delphi pisałem jakiś prosty progs do sprawdzania baterii w lapku + alarm wav (jak zasilacz podłączony, to reaguje odpoiwednio (znaki zapytania pokzuje wg tego kodu niżej), jak odłączony i bateria chodzi to pokazuje ile min itd), łap fragment kodu, o ile chcesz:
procedure TForm1.Timer1Timer(Sender: TObject);
var
stan: TSystemPowerStatus;
current: Cardinal;
pozycja: Integer;
begin
GetSystemPowerStatus(stan);
if (stan.BatteryFlag <> 128) then
begin
current:= stan.BatteryLifeTime div 60;
if (current < 1000) then
begin
Label1.Caption:= 'Pozostało: ' + IntToStr(current) + ' minut';
end else
begin
Label1.Caption:= 'Pozostało: ' + '???' + ' minut';
end;
Label2.Caption:= 'Poziom baterii: ' + IntToStr(stan.BatteryLifePercent) + '%';
ProgressBar1.Position:= stan.BatteryLifePercent;
pozycja:= stan.BatteryLifePercent;
//ustaw kolor progress bara
case (pozycja) of
50..100: ProgressBar1.State:= pbsNormal;
20..49: ProgressBar1.State:= pbsPaused;
0..19: ProgressBar1.State:= pbsError;
end;
//jesli bateria = 20% to odegraj dzwiek
if ( (odegrany_20 = False) and (stan.BatteryLifePercent = 20) ) then
begin
sndPlaySound(PChar(sciezka + '20.wav'), SND_FILENAME or SND_ASYNC);
odegrany_20:= True;
end;
//jesli bateria < 20% i juz byl alarm to odegrany:= False;
if ( (odegrany_20 = True) and (stan.BatteryLifePercent < 20) ) then
begin
odegrany_20:= False;
end;
//jesli bateria = Edit1 to odegraj alarm
if ( (Edit1.Text <> '') and (stan.BatteryLifePercent = StrToInt(Edit1.Text)) ) then
begin
if (alarm = False) then
begin
alarm:= True;
sndPlaySound(PChar(sciezka + 'beep.wav'), SND_FILENAME or SND_ASYNC or SND_LOOP);
end;
end;
end;
end;