home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d56 / MSYSINFO.ZIP / Source / MSI_APM.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-07-24  |  3.7 KB  |  120 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       MiTeC System Information Component              }
  5. {               APM Detection Part                      }
  6. {           version 6.0 for Delphi 5,6                  }
  7. {                                                       }
  8. {       Copyright ⌐ 1997,2001 Michal Mutl               }
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. {$INCLUDE MITEC_DEF.INC}
  13.  
  14. unit MSI_APM;
  15.  
  16. interface
  17.  
  18. uses
  19.   SysUtils, Windows, Classes;
  20.  
  21. type
  22.   TPowerStatus = (psUnknown, psOffline, psOnline);
  23.   
  24.   TBatteryStatus = (bsUnknown, bsHigh, bsLow, bsCritical, bsCharging, bsNoBattery);
  25.  
  26.   TAPM = class(TPersistent)
  27.   private
  28.     FBatteryLifePercent: Byte;
  29.     FBatteryLifeFullTime: DWORD;
  30.     FBatteryLifeTime: DWORD;
  31.     FACPowerStatus: TPowerStatus;
  32.     FBatteryChargeStatus: TBatteryStatus;
  33.   public
  34.     procedure GetInfo;
  35.     procedure Report(var sl :TStringList);
  36.   published
  37.     property ACPowerStatus :TPowerStatus read FACPowerStatus {$IFNDEF D6PLUS} write FACPowerStatus {$ENDIF} stored false;
  38.     property BatteryChargeStatus :TBatteryStatus read FBatteryChargeStatus {$IFNDEF D6PLUS} write FBatteryChargeStatus {$ENDIF} stored false;
  39.     property BatteryLifePercent :Byte read FBatteryLifePercent {$IFNDEF D6PLUS} write FBatteryLifePercent {$ENDIF} stored false;
  40.     property BatteryLifeTime :DWORD read FBatteryLifeTime {$IFNDEF D6PLUS} write FBatteryLifeTime {$ENDIF} stored false;
  41.     property BatteryLifeFullTime :DWORD read FBatteryLifeFullTime {$IFNDEF D6PLUS} write FBatteryLifeFullTime {$ENDIF} stored false;
  42.   end;
  43.  
  44. implementation
  45.  
  46. uses
  47.   MiTeC_Routines;
  48.  
  49. { TAPM }
  50.  
  51. procedure TAPM.GetInfo;
  52. var
  53.   PS :TSystemPowerStatus;
  54.   OK: Boolean;
  55. begin
  56.   FACPowerStatus:=psUnknown;
  57.   FBatteryChargeStatus:=bsUnknown;
  58.   FBatteryLifePercent:=0;
  59.   FBatteryLifeTime:=0;
  60.   FBatteryLifeFullTime:=0;
  61.   ok:=GetSystemPowerStatus(PS);
  62.   if OK then begin
  63.     case PS.ACLineStatus of
  64.       0 : FACPowerStatus:=psOffLine;
  65.       1 : FACPowerStatus:=psOnLine;
  66.       else FACPowerStatus:=psUnknown;
  67.     end;
  68.     if (PS.BatteryFlag or 1)=1 then
  69.       FBatteryChargeStatus:=bsHigh
  70.     else
  71.       if (PS.BatteryFlag or 2)=2 then
  72.         FBatteryChargeStatus:=bsLow
  73.       else
  74.         if (PS.BatteryFlag or 4)=4 then
  75.           FBatteryChargeStatus:=bsCritical
  76.         else
  77.           if (PS.BatteryFlag or 8)=8 then
  78.             FBatteryChargeStatus:=bsCharging
  79.           else
  80.             if (PS.BatteryFlag or 128)=128 then
  81.               FBatteryChargeStatus:=bsNoBattery
  82.             else
  83.               FBatteryChargeStatus:=bsUnknown;
  84.     FBatteryLifePercent:=PS.BatteryLifePercent;
  85.     FBatteryLifeTime:=PS.BatteryLifeTime;
  86.     FBatteryLifeFullTime:=PS.BatteryFullLifeTime;
  87.   end;
  88. end;
  89.  
  90. procedure TAPM.Report(var sl: TStringList);
  91. var
  92.   s: string;
  93. begin
  94.   with sl do begin
  95.     Add('[Advanced Power Management]');
  96.     case ACPowerStatus of
  97.       psUnknown: s:='Unknown';
  98.       psOnline: s:='Online';
  99.       psOffline: s:='Offline';
  100.     end;
  101.     Add(Format('ACPowerStatus=%s',[s]));
  102.     case BatteryChargeStatus of
  103.       bsUnknown: s:='Unknown';
  104.       bsHigh: s:='High';
  105.       bsLow: s:='Low';
  106.       bsCritical: s:='Critical';
  107.       bsCharging: s:='Charging';
  108.       bsNoBattery: s:='No Battery';
  109.     end;
  110.     Add(Format('BatteryChargeStatus=%s',[s]));
  111.     if BatteryLifePercent<=100 then begin
  112.       Add(Format('BattreyLifeFullTime=%s',[FormatSeconds(BatteryLifeFullTime,true,false,false)]));
  113.       Add(Format('BatteryLifeTime=%s',[FormatSeconds(BatteryLifeTime,true,false,false)]));
  114.     end;
  115.   end;
  116. end;
  117.  
  118.  
  119. end.
  120.