在Delphi中使用RegisterPowerSettingNotification [英] RegisterPowerSettingNotification use in Delphi
本文介绍了在Delphi中使用RegisterPowerSettingNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何结合使用 RegisterPowerSettingNotification 在Delphi XE2中 GUID_MONITOR_POWER_ON ?
How to use the RegisterPowerSettingNotification in conjuction with GUID_MONITOR_POWER_ON in Delphi XE2?
推荐答案
您必须致电使用所需的GUID 电源设置GUID ,用于注册应用程序以接收特定电源设置事件的电源设置通知,如果不再需要,则调用取消注册PowerSettingNotification 。
You have to call RegisterPowerSettingNotification with the desired GUID Power Setting GUIDs to registers the application to receive power setting notifications for a specific power setting event, if not needed anymore the call UnregisterPowerSettingNotification.
一个delphi示例可能看起来像这样:
A delphi example could look like this:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
GUID_MONITOR_POWER_ON: TGUID = '{02731015-4510-4526-99e6-e5a17ebd1aea}';
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FHPOWERNOTIFY: THandle;
protected
procedure WM_POWERBROADCAST(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';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FHPOWERNOTIFY := RegisterPowerSettingNotification(Handle,
@GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnregisterPowerSettingNotification(FHPOWERNOTIFY);
end;
procedure TForm1.WM_POWERBROADCAST(var Msg: TMessage);
begin
if PPOWERBROADCAST_SETTING(Msg.LParam)^.Data[0] = 0 then
Memo1.Lines.Add('Off')
else
Memo1.Lines.Add('ON')
end;
end.
这篇关于在Delphi中使用RegisterPowerSettingNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文