Einzelnen Beitrag anzeigen

schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#6

Re: Standby zurück wird nicht erkannt?

  Alt 30. Okt 2009, 22:56
Ergänzung:

Ich habe es auch noch mit folgendem Code versucht:
Delphi-Quellcode:
unit NonVCL_WM;

interface

uses
  Windows,Classes,Messages;

type
  { Our class derived from TComponent
    or another ancestor class }

  TMyClass = class(TComponent)
  private
    fHWnd: HWND;
      { field to store the window handle }
  protected
    procedure WndMethod(var Msg: TMessage); virtual;
      { window proc - called by Windows to handle
        messages passed to our hidden window }

  public
     constructor Create(AOwner: TComponent); override;
       { create hidden window here: store handle in fHWnd}
     destructor Destroy; override;
       { free hidden window here }
  end;

var
  MyMessageClass : TMyClass;

implementation

uses
  PowerWatch,SysUtils;

function TranslatePowerBroadcast(const Msg: Cardinal): string;
begin
  case Msg of
    WM_POWERBROADCAST: Result := 'WM_POWERBROADCAST';

    PBT_APMQUERYSUSPEND: Result := 'PBT_APMQUERYSUSPEND, Info: Request for permission to suspend. In Windows Server 2008 and Windows Vista, use the SetThreadExecutionState function instead.';
    PBT_APMQUERYSTANDBY: Result := 'PBT_APMQUERYSTANDBY';

    PBT_APMQUERYSUSPENDFAILED: Result := 'PBT_APMQUERYSUSPENDFAILED';
    PBT_APMQUERYSTANDBYFAILED: Result := 'PBT_APMQUERYSTANDBYFAILE, Info: Suspension request denied. In Windows Server 2008 and Windows Vista, use SetThreadExecutionState instead.D';

    PBT_APMSUSPEND: Result := 'PBT_APMSUSPEND, Info: System is suspending operation.';
    PBT_APMSTANDBY: Result := 'PBT_APMSTANDBY';

    PBT_APMRESUMECRITICAL: Result := 'PBT_APMRESUMECRITICAL, Info: Operation resuming after critical suspension. In Windows Server 2008 and Windows Vista, use PBT_APMRESUMEAUTOMATIC instead.';
    PBT_APMRESUMESUSPEND: Result := 'PBT_APMRESUMESUSPEND, Info: Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.';
    PBT_APMRESUMESTANDBY: Result := 'PBT_APMRESUMESTANDBY';

    //PBTF_APMRESUMEFROMFAILURE: Result := 'PBTF_APMRESUMEFROMFAILURE';

    PBT_APMBATTERYLOW: Result := 'PBT_APMBATTERYLOW, Info: Battery power is low. In Windows Server 2008 and Windows Vista, use PBT_APMPOWERSTATUSCHANGE instead.';
    PBT_APMPOWERSTATUSCHANGE: Result := 'PBT_APMPOWERSTATUSCHANGE, Info: Power status has changed.';
    //PBT_POWERSETTINGCHANGE: Result := 'PBT_POWERSETTINGCHANGE, Info: A power setting change event has been received.';

    PBT_APMOEMEVENT: Result := 'PBT_APMOEMEVENT, Info: OEM-defined event occurred. In Windows Server 2008 and Windows Vista, this event is not available because these operating systems support only ACPI; APM BIOS events are not supported.';
    PBT_APMRESUMEAUTOMATIC: Result := 'PBT_APMRESUMEAUTOMATIC, Info: Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.';
  else
    Result := 'Unknown Message "'+IntToStr(Msg)+'"';
  end;
end;

constructor TMyClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  // Create hidden window using WndMethod as window proc
  fHWnd := AllocateHWnd(WndMethod);

end;

destructor TMyClass.Destroy;
begin

  // Destroy hidden window
  DeallocateHWnd(fHWnd);

  inherited Destroy;
end;

procedure TMyClass.WndMethod(var Msg : TMessage);
begin

  case Msg.Msg of

   WM_POWERBROADCAST: begin
    // windows powermanagement message

    FormPowerWatch.Memo1.Lines.Append(TimeToStr(now) + ' Msg: '+TranslatePowerBroadcast(Msg.Msg));
    FormPowerWatch.Memo1.Lines.Append(TimeToStr(now) + ' WParam: '+TranslatePowerBroadcast(Msg.WParam));
    FormPowerWatch.Memo1.Lines.Append('');
   end;

  end;

    // pass to DefWindowProc and record result
    Msg.Result := DefWindowProc(fHWnd, Msg.Msg,
      Msg.WParam, Msg.LParam);
end;

end.
(Die FormPowerWatch dient nurmehr als Dummy für das Memo, die WM Message wurde entfernt)

Jedoch auch hier wird nur das zurückkommen vom Standby erkannt. Nix mit PBT_APMSUSPEND! Nur PBT_APMRESUMEAUTOMATIC & PBT_APMRESUMESUSPEND.
Delphi 2010, Update 4 & 5
  Mit Zitat antworten Zitat