unit PowerButton;
///////////////////////////////////////////////////////////////////////////////////////
//Dies ist eine Komponente um den Powerknopf anzusteuern.
//Eigenschaften:
//PowerOffEnable:boolean
// >false lässt den Pc nicht mehr herunterfahren
//Ereignisse:
// OnPowerbuttonpress
// >Wird ausgeführt wenn der Powerbutton gedrückt wurde
//
//Programmed by CTV => [url]www.ctvnet.ch[/url]
//
//Komponente darf frei für alles verwendet werden copyright darf nicht entfernt werden
///////////////////////////////////////////////////////////////////////////////////////
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Menus, ShellApi, ExtCtrls;
type
TPowerButton =
class(TComponent)
private
FHooked: Boolean;
FOnPowerbuttonPress : TNotifyEvent;
PPowerOffEnable:Boolean;
function MessageHook(
var Msg: TMessage): Boolean;
protected
procedure DoPowerbuttonPress;
dynamic;
public
Version,Hersteller:
string;
IResultHi,IResultLo,ILParamHi,ILParamLo,IWParamHi,ILParam,IWParamLo,IWparam,Imsg,IResult:integer;
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
{events}
property OnPowerbuttonPress: TNotifyEvent
read FOnPowerbuttonPress
write FOnPowerbuttonPress;
{properties}
property PowerOffEnable : boolean
read PPowerOffEnable
write PPowerOffEnable;
end;
procedure Register;
implementation
const
PBT_APMQUERYSUSPEND = 536;
{Request for permission to suspend.}
procedure Register;
begin
RegisterComponents('
Zusätzlich', [TPowerButton]);
end;
constructor TPowerButton.create(AOwner : TComponent);
begin
inherited Create(AOwner);
Version:='
1.0.0.0';
Hersteller:='
CTVNet.ch';
FHooked := False;
if not (csDesigning
in ComponentState)
then
begin
Application.HookMainWindow(MessageHook);
FHooked := True;
end;
end;
Procedure TPowerButton.DoPowerbuttonPress;
begin
if Assigned(FOnPowerbuttonPress)
then FOnPowerbuttonPress(Self);
end;
function TPowerButton.MessageHook(
var Msg: TMessage): Boolean;
begin
IResultHi:=msg.ResultHi;
IResultLo:=msg.ResultLo;
ILParamHi:=msg.LParamHi;
ILParamLo:=msg.LParamLo;
IWParamHi:=msg.WParamHi;
ILParam:=msg.LParam;
IWParamLo:=msg.WParamLo;
Imsg:=msg.Msg;
IResult:=msg.result;
IWparam:=msg.WParam;
if (msg.msg=PBT_APMQUERYSUSPEND)
and (msg.WParam=0)
then //win95/98
begin
if PPowerOffEnable = false
then
begin
msg.Result := PWR_FAIL;
end;
end;
if (msg.msg=PBT_APMQUERYSUSPEND)
and (msg.WParam=0)
then //winNT,2k,XP
begin
if PPowerOffEnable = false
then
begin
msg.Result := BROADCAST_QUERY_DENY;
end;
end;
if (msg.msg=PBT_APMQUERYSUSPEND)
and (msg.WParam=0)
then //excute Event
begin
DoPowerbuttonPress;
end;
end;
destructor TPowerButton.Destroy;
begin
if FHooked
then Application.UnhookMainWindow(MessageHook);
inherited Destroy;
end;
end.