核心提示:1、捕获wm_powerbroadcast消息,判断wParam的值,如下PBT_APMRESUMESUSPEND唤醒时PBT_APMSUSPEND 待机时 unit Unit1;interfaceu...
1、捕获wm_powerbroadcast消息,判断wParam的值,如下
PBT_APMRESUMESUSPEND 唤醒时
PBT_APMSUSPEND 待机时
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
const
PBT_APMQUERYSUSPEND = 0;
PBT_APMRESUMECRITICAL = 6;
PBT_APMRESUMESUSPEND = 7;
type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMPowerBC(var msg: TMessage); message WM_PowerBroadCast;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.WMPowerBC(var msg: TMessage);
begin
case msg.Wparam of
PBT_APMQUERYSUSPEND : msg.Result:=0;//待机
PBT_APMRESUMECRITICAL ,
PBT_APMRESUMESUSPEND : showmessage('resume');//唤醒
end;
end;