Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #4  
Antiguo 25-07-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 24
ixMike Va por buen camino
mmmm

No funciona. ¿En qué unidad están AllocateHWnd y DeallocateHWnd?

Utilizo Delphi 3 standar.



El código lo necesitaba para un componente, el cual analiza el cambio de estado de CapsLock, NumLock y ScrollLock. Para ello necesitaba un HotKey, y por eso necesitaba el Handle de la ventana. Este es el código (por si a alguien se le ocurre cómo solucionar el problema):

Código Delphi [-]
 
unit KeyState;
 
interface
 
uses
  Windows, Messages, Classes;
 
type
  TKeyState = class(TComponent)
  private
    aCaps,
    aNum,
    aScroll: ATOM;
    Active,
    FCapsLock,
    FNumLock,
    FScrollLock: Boolean;
    FHotKeyName: String;
    FOnChange: TNotifyEvent;
 
    InternalWindow: HWnd;
    Procedure WndProc(var Msg: TMessage); virtual;
 
//    Procedure WMHotKey(var msg: TWMHotKey); message WM_HOTKEY;
 
  public
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
 
    Procedure Start;
    Procedure Stop;
 
    Property CapsLock: Boolean read FCapsLock;
    Property NumLock: Boolean read FNumLock;
    Property ScrollLock: Boolean read FScrollLock;
    Property HotKeyName: String read FHotKeyName write FHotKeyName;
 
  published
    Property OnChange: TNotifyEvent read FOnChange write FOnChange;
  end;
 
procedure Register;
 
implementation
 
{procedure TKeyState.WMHotKey(var Msg: TWMHotKey);
var
 K: TKeyBoardState;
begin
GetKeyBoardState(K);
If Msg.HotKey=aCaps then FCapsLock:=not FCapsLock;
If Msg.HotKey=aNum then FNumLock:=not FNumLock;
If Msg.HotKey=aScroll then FScrollLock:=not FScrollLock;
K[VK_CAPITAL]:=Integer(FCapsLock);
K[VK_NUMLOCK]:=Integer(FNumLock);
K[VK_SCROLL]:=Integer(FScrollLock);
SetKeyBoardState(K);
If Assigned(FOnChange) then FOnChange(Self);
end;}
 
Procedure TKeyState.WndProc(var Msg: TMessage);
var
 K: TKeyBoardState;
begin
If Msg.Msg=WM_HOTKEY then
 with TWMHotKey(Msg) do
   begin
   GetKeyBoardState(K);
   If HotKey=aCaps then FCapsLock:=not FCapsLock;
   If HotKey=aNum then FNumLock:=not FNumLock;
   If HotKey=aScroll then FScrollLock:=not FScrollLock;
   K[VK_CAPITAL]:=Integer(FCapsLock);
   K[VK_NUMLOCK]:=Integer(FNumLock);
   K[VK_SCROLL]:=Integer(FScrollLock);
   SetKeyBoardState(K);
   If Assigned(FOnChange) then FOnChange(Self);
   end;
end;
 
Constructor TKeyState.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Active:=False;
FCapsLock:=GetKeyState(VK_CAPITAL)=1;
FNumLock:=GetKeyState(VK_NUMLOCK)=1;
FScrollLock:=GetKeyState(VK_SCROLL)=1;
end;
 
Destructor TKeyState.Destroy;
begin
If Active then Stop;
inherited Destroy;
end;
 
Procedure TKeyState.Start;
begin
If FHotKeyName='' then Exit;
InternalWindow:=AllocateHWnd(WndProc);
aCaps:=GlobalAddAtom(PChar(FHotKeyName+'C'));
aNum:=GlobalAddAtom(PChar(FHotKeyName+'N'));
aScroll:=GlobalAddAtom(PChar(FHotKeyName+'S'));
RegisterHotKey(InternalWindow, aCaps, 0, VK_CAPITAL);
RegisterHotKey(InternalWindow, aNum, 0, VK_NUMLOCK);
RegisterHotKey(InternalWindow, aScroll, 0, VK_SCROLL);
Active:=True;
end;
 
Procedure TKeyState.Stop;
begin
If not Active then Exit;
UnRegisterHotKey(InternalWindow, aCaps);
UnRegisterHotKey(InternalWindow, aNum);
UnRegisterHotKey(InternalWindow, aScroll);
GlobalDeleteAtom(aCaps);
GlobalDeleteAtom(aNum);
GlobalDeleteAtom(aScroll);
DeallocateHWnd(InternalWindow);
Active:=False;
end;
 
procedure Register;
begin
  RegisterComponents('LunatikO', [TKeyState]);
end;
 
end.
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Handle disabled carlos_nielsen API de Windows 11 15-01-2007 02:23:23
ayuda comparar Handle JerS API de Windows 3 30-10-2006 20:19:01
Ayuda con el procedimiento Notification de Tcomponent Punzo OOP 6 11-05-2006 23:52:42
Casting de TComponent en TEdit jamonete2 Varios 2 12-06-2005 15:56:19
WM_DEVICECHANGE en un TComponent NeWNeO API de Windows 5 28-05-2004 16:12:07


La franja horaria es GMT +2. Ahora son las 06:40:29.


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