unit nduComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Forms, Dialogs;
type
TnduWindowHook =
function(
var Message: TMessage): Boolean
of Object;
TnduOnReceiveUserMessage =
procedure(Msg: Cardinal; wParam, lParam: Integer;
var Handled: Boolean)
of object;
TnduOnReceiveOtherMessage =
procedure(
var Handled: Boolean)
of object;
TnduComponent =
class(TComponent)
function MessageHook(
var Msg: TMessage): Boolean;
virtual;
private
FHooked: Boolean;
FOnReceiveUserMessage: TnduOnReceiveUserMessage;
procedure SetOnReceiveUserMessage(
const Value: TnduOnReceiveUserMessage);
protected
function DoUserMessage(Msg: TMessage): Boolean;
dynamic;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
property OnReceiveUserMessage: TnduOnReceiveUserMessage
read FOnReceiveUserMessage
write SetOnReceiveUserMessage;
end;
implementation
{ TnduCompoent }
constructor TnduComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHooked := False;
if not (csDesigning
in ComponentState)
then
begin
Application.HookMainWindow(MessageHook);
FHooked := True;
end;
end;
destructor TnduComponent.Destroy;
begin
if FHooked
then
begin
Application.UnhookMainWindow(MessageHook);
end;
inherited Destroy;
end;
function TnduComponent.DoUserMessage(Msg: TMessage): Boolean;
begin
Result := False;
if Assigned(FOnReceiveUserMessage)
then
begin
FOnReceiveUserMessage(Msg.Msg, Msg.wParam, Msg.LParam, Result);
end;
end;
function TnduComponent.MessageHook(
var Msg: TMessage): Boolean;
begin
Result := False;
end;
procedure TnduComponent.SetOnReceiveUserMessage(
const Value: TnduOnReceiveUserMessage);
begin
FOnReceiveUserMessage := Value;
end;
end.