Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-04-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
TComponent y Handle

Hola a todos,

¿alguien sabe cómo añadirle la propiedad Handle a un TComponent, con todo lo que ello implica?

Es que necesito crear un componente no visible que tiene que recibir un mensaje (concretamente el WM_HOTKEY), y procesarlo.

Gracias desde ya.
Responder Con Cita
  #2  
Antiguo 24-04-2007
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
La componente debe crear una ventana y dirigir a ella los mensajes. Eso puedes hacerlo con AllocateHWnd y DeallocateHWnd. En mi página puedes ver la componente TCDChange, en donde se ejemplifica eso.

// Saludos
Responder Con Cita
  #3  
Antiguo 11-05-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
Muchísimas gracias, Roman.

Y perdón por la tardanza, he estado de exámenes.
Responder Con Cita
  #4  
Antiguo 25-07-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
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
  #5  
Antiguo 11-10-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
Hola.

¿Alguien tiene solución al problema? Es que Roman me dejó a medio, y como nadie lo ha vuelto a ver...


Muchas gracias (y, Roman, vuelve pronto).
Responder Con Cita
  #6  
Antiguo 12-10-2007
Avatar de aeff
aeff aeff is offline
Miembro
 
Registrado: oct 2006
Ubicación: Cuba, Guantánamo
Posts: 348
Poder: 18
aeff Va camino a la fama
hola, prueba con estas funciones o busca en la ayuda de Delphi al respecto, CallWindowProc, DefDlgProc, WindowProc, SetWindowLong, RegisterClass, debe haber algo por ahi,

ahora realmente estoy contra el tiempo, luego estudiare al respecto, cuando venha deñ colegio,!!

saludos
aeff!
Responder Con Cita
Respuesta



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 11:04:54.


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