請問各位高手,如何得知電源電池的百分比容量 |
答題得分者是:timhuang
|
ATEIN
高階會員 發表:105 回覆:320 積分:125 註冊:2002-07-05 發送簡訊給我 |
|
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
Hi, 請使用 GetSystemPowerStatus 這個 api 即可, 範例如下,
var sps: TSystemPowerStatus; status: string; begin if GetSystemPowerStatus(sps) then begin case sps.ACLineStatus of 0: status := status 'ACLineStatus: Offline'#13#10; 1: status := status 'ACLineStatus: Online'#13#10; 255: status := status 'ACLineStatus: Unkonwn'#13#10; end; case sps.BatteryFlag of 1: status := status 'BatteryFlag: High'#13#10; 2: status := status 'BatteryFlag: Low'#13#10; 4: status := status 'BatteryFlag: Critical'#13#10; 8: status := status 'BatteryFlag: Charging'#13#10; 128: status := status 'BatteryFlag: No system battery'#13#10; 255: status := status 'BatteryFlag: Unknown status'#13#10; end; if sps.BatteryLifePercent = 255 then status := status 'BatteryLifePercent: unknown' else status := status 'BatteryLifePercent: ' IntToStr(sps.BatteryLifePercent) '%'; ShowMessage(status); end else ShowMessage('error to get SystemPowerStatus'); end; |
nlj859
資深會員 發表:139 回覆:375 積分:322 註冊:2004-03-20 發送簡訊給我 |
Hello ATEIN, 請參考BCB寫法:
_SYSTEM_POWER_STATUS sps; AnsiString status=""; if (GetSystemPowerStatus(&sps)) { switch (sps.ACLineStatus) { case 0: status = status "ACLineStatus: Offline\n"; break; case 1: status = status "ACLineStatus: Online\n"; break; case 255: status = status "ACLineStatus: Unkonwn\n"; } switch (sps.BatteryFlag) { case 1: status = status "BatteryFlag: High\n"; break; case 2: status = status "BatteryFlag: Low\n"; break; case 4: status = status "BatteryFlag: Critical\n"; break; case 8: status = status "BatteryFlag: Charging\n"; break; case 128: status = status "BatteryFlag: No system battery\n"; break; case 255: status = status "BatteryFlag: Unknown status\n"; } if (sps.BatteryLifePercent == 255) status = status "BatteryLifePercent: unknown"; else status = status "BatteryLifePercent: " IntToStr(sps.BatteryLifePercent) "%"; ShowMessage(status); } else ShowMessage("error to get SystemPowerStatus");SstemPowerStatus: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/getsystempowerstatus.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/system_power_status_str.asp 發表人 - nlj859 於 2004/09/26 12:14:34 |
ATEIN
高階會員 發表:105 回覆:320 積分:125 註冊:2002-07-05 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |