Einzelnen Beitrag anzeigen

Benutzerbild von Björn Ole
Björn Ole

Registriert seit: 11. Jul 2008
166 Beiträge
 
Delphi XE Professional
 
#4

AW: Bemerken/Abfangen wenn der Monitor an geht

  Alt 25. Okt 2010, 01:46
Nabend.
Funktioniert ab Vista, Stichwort: MSDN-Library durchsuchenRegisterPowerSettingNotification
Delphi-Quellcode:
TForm1 = class(TForm)
  private
    FPowerSetting: THandle;
  protected
    procedure WmPowerBrotkasten(var Msg: TMessage); message WM_POWERBROADCAST;
  end;

function RegisterPowerSettingNotification(hRecipient: THandle; PowerSettingGuid: PGUID;
  Flags: DWORD): THandle; stdcall; external 'user32.dll';
function UnregisterPowerSettingNotification(Handle: THandle): BOOL; stdcall; external 'user32.dll';

{...}

// Start monitoring
const
  GUID_MONITOR_POWER_ON: TGUID = '{02731015-4510-4526-99e6-e5a17ebd1aea}';
begin
  FPowerSetting := RegisterPowerSettingNotification(Handle, @GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
end;

// End monitoring
begin
  UnregisterPowerSettingNotification(FPowerSetting);
end;

// Receive notifications
procedure TForm1.WmPowerBrotkasten(var Msg: TMessage);
var
  pbSetting: POWERBROADCAST_SETTING;
begin
  pbSetting := PPOWERBROADCAST_SETTING(Msg.LParam)^;
  if pbSetting.Data[0] = 0 then
    // Monitor turned off
  else if pbSetting.Data[0] = 1 then
    // Monitor turned on
end;
  Mit Zitat antworten Zitat