Control Name | Unit | Class |
RX Application Events | RxHook | TRxWindowHook |
Description:
This class allows the
creation of a "windows system hook". In other words,
register an event with the windows event system so that it can be
processed by your application instead. As it's name implies, it
is not easy to understand what it does.
In other words, if you do not have the source code Make an
extension to a component that does not have the source code, or
is difficult to modify.
Property
WinControl
Declaration:
WinControl: TWinControl;
This is the component to "hook" to.
Event
AfterMessage
Declaration:
AfterMessage: THookMessageEvent;
AfterMessage event is triggered after a message generated from that particular control is passed.
Event
BeforeMessage
Declaration:
BeforeMessage: THookMessageEvent;
BeforeMessage event is triggered before a message is generated
from that particular control being monitored.
Type
THookMessageEvent
Declaration:
THookMessageEvent = procedure (Sender: TObject; var Msg:
TMessage; var Handled: Boolean) of object;
THookMessageEvent is the type of the BeforeMessage and AfterMessage events of the TRxWindowHook component. The Handled parameter have a sence only in the BeforeMessage event.
Routine FindVirtualMethodIndex
Declaration:
function FindVirtualMethodIndex(AClass: TClass; MethodAddr:
Pointer): Integer;
FindVirtualMethodIndex example:
type THookForm = class(TForm)
protected
__procedure WndProc(var Message: TMessage);
override;
end;
{...}
WndProcSeq :=
FindVirtualMethodIndex(THookForm, @THookForm.WndProc);
{...}
Routine GetVirtualMethodAddress
Declaration:
function GetVirtualMethodAddress(AClass: TClass; AIndex:
Integer): Pointer;
GetVirtualMethodAddress
example:
Method := GetVirtualMethodAddress(TForm1, 1);
Routine SetVirtualMethodAddress
Declaration:
function SetVirtualMethodAddress(AClass: TClass; AIndex: Integer;
NewAddress: Pointer): Pointer;
SetVirtualMethodAddress hooks the custom control AClass and specific type AIndex and linking it to new address.
SetVirtualMethodAddress example:
Next example shows how you can replace address of virtual method
WndProc for descendant of TForm:
{ THookForm }
type
THookForm = class(TForm)
protected
__procedure WndProc(var Message: TMessage);
override;
end;
procedure THookForm.WndProc(var Message: TMessage);
var I: Integer;
begin
__inherited WndProc(Message);
__if (Message.Msg = WM_NCHITTEST) then
__try
____{ your specific event handler }
__except
____Application.HandleException(Self);
__end;
end;
Replace and restore method address:
type PClass = ^TClass;
var SaveMethod: TWndMethod;
procedure SetHook(AForm: TForm);
var MethodIndex: Integer;
begin
__MethodIndex :=
FindVirtualMethodIndex(THookForm, @THookForm.WndProc);
__@SaveMethod :=
SetVirtualMethodAddress(PClass(Form)^,
__MethodIndex, @THookForm.WndProc);
end;
procedure ReleaseHook(AForm:
TForm);
var MethodIndex: Integer;
begin
__if Assigned(SaveMethod) then
__begin
____MethodIndex :=
FindVirtualMethodIndex(THookForm, @THookForm.WndProc);
____SetVirtualMethodAddress(PClass(Form)^,
MethodIndex, @SaveMethod);
____SaveMethod := nil;
__end;
end;
Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000