home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kompon / d2345 / MSYSINFO.ZIP / Source / MSI_APM.PAS < prev    next >
Pascal/Delphi Source File  |  2001-05-21  |  4KB  |  128 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       MiTeC System Information Component              }
  5. {               APM Detection Part                      }
  6. {           version 5.4 for Delphi 3,4,5                }
  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 write FACPowerStatus stored false;
  38.     property BatteryChargeStatus :TBatteryStatus read FBatteryChargeStatus write FBatteryChargeStatus stored false;
  39.     property BatteryLifePercent :Byte read FBatteryLifePercent write FBatteryLifePercent stored false;
  40.     property BatteryLifeTime :DWORD read FBatteryLifeTime write FBatteryLifeTime stored false;
  41.     property BatteryLifeFullTime :DWORD read FBatteryLifeFullTime write FBatteryLifeFullTime 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.   try
  57.  
  58.   FACPowerStatus:=psUnknown;
  59.   FBatteryChargeStatus:=bsUnknown;
  60.   FBatteryLifePercent:=0;
  61.   FBatteryLifeTime:=0;
  62.   FBatteryLifeFullTime:=0;
  63.   ok:=GetSystemPowerStatus(PS);
  64.   if OK then begin
  65.     case PS.ACLineStatus of
  66.       0 : FACPowerStatus:=psOffLine;
  67.       1 : FACPowerStatus:=psOnLine;
  68.       else FACPowerStatus:=psUnknown;
  69.     end;
  70.     if (PS.BatteryFlag or 1)=1 then
  71.       FBatteryChargeStatus:=bsHigh
  72.     else
  73.       if (PS.BatteryFlag or 2)=2 then
  74.         FBatteryChargeStatus:=bsLow
  75.       else
  76.         if (PS.BatteryFlag or 4)=4 then
  77.           FBatteryChargeStatus:=bsCritical
  78.         else
  79.           if (PS.BatteryFlag or 8)=8 then
  80.             FBatteryChargeStatus:=bsCharging
  81.           else
  82.             if (PS.BatteryFlag or 128)=128 then
  83.               FBatteryChargeStatus:=bsNoBattery
  84.             else
  85.               FBatteryChargeStatus:=bsUnknown;
  86.     FBatteryLifePercent:=PS.BatteryLifePercent;
  87.     FBatteryLifeTime:=PS.BatteryLifeTime;
  88.     FBatteryLifeFullTime:=PS.BatteryFullLifeTime;
  89.   end;
  90.  
  91.   except
  92.     on e:Exception do begin
  93.       MessageBox(0,PChar(e.message),'TAPM.GetInfo',MB_OK or MB_ICONERROR);
  94.     end;
  95.   end;
  96. end;
  97.  
  98. procedure TAPM.Report(var sl: TStringList);
  99. var
  100.   s: string;
  101. begin
  102.   with sl do begin
  103.     Add('[Advanced Power Management]');
  104.     case ACPowerStatus of
  105.       psUnknown: s:='Unknown';
  106.       psOnline: s:='Online';
  107.       psOffline: s:='Offline';
  108.     end;
  109.     Add(Format('ACPowerStatus=%s',[s]));
  110.     case BatteryChargeStatus of
  111.       bsUnknown: s:='Unknown';
  112.       bsHigh: s:='High';
  113.       bsLow: s:='Low';
  114.       bsCritical: s:='Critical';
  115.       bsCharging: s:='Charging';
  116.       bsNoBattery: s:='No Battery';
  117.     end;
  118.     Add(Format('BatteryChargeStatus=%s',[s]));
  119.     if BatteryLifePercent<=100 then begin
  120.       Add(Format('BattreyLifeFullTime=%s',[FormatSeconds(BatteryLifeFullTime,true,false,false)]));
  121.       Add(Format('BatteryLifeTime=%s',[FormatSeconds(BatteryLifeTime,true,false,false)]));
  122.     end;
  123.   end;
  124. end;
  125.  
  126.  
  127. end.
  128.