Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #10  
Antiguo 31-03-2005
NPIdea NPIdea is offline
Miembro
 
Registrado: feb 2005
Posts: 121
Poder: 20
NPIdea Va por buen camino
Solucionadooooooooooo

Jejeje, pues he encontrado este componente, como no, en otra gran página sobre el fascinante mundo de Delphi, despues de probar montones de formas, con privilegiios, mensajes, capturas, etc, etc. Y lo peor es que cada vez que se pulsa el maldito botón hay que arrancar el sistema.

Sin más rollos ni dilaciones os presento a PowerButton (Lo publico tal como lo he encontrado):

Código Delphi [-]
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 => www.ctvnet.ch
//
//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, Dialogs;
 
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.

Última edición por roman fecha: 31-03-2005 a las 18:58:05.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 17:48:14.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi