EKIM
asked on
traping WM_RBUTTONDBLCLK message in a component
hi all
I want to write a component that catch the WM_RBUTTONDBLCLK message.
The final goal is a non visual component providing an OnRightDbClick event.
So, how my component can catch it's owner's message ?
hope it's clear.
Thanks
Mike
I want to write a component that catch the WM_RBUTTONDBLCLK message.
The final goal is a non visual component providing an OnRightDbClick event.
So, how my component can catch it's owner's message ?
hope it's clear.
Thanks
Mike
Application.HookMainWindow allows to get your private message feed.
hello EKIM, here's the code for a component that will do the right mouse button double click thing. It uses the Application.OnMessage to get the WM_RBUTTONDBLCLK. You should look into the Application.OnMessage if you are going to deal with windows messages. Oh, and in a component, it might be really UNwise to set the Handled to True, since it will knockout that message in ALL the forms of that app.
- - - - - - - - - - - - - - - - - -
unit RButDblClk;
interface
uses
SysUtils, Windows, Messages, Classes, Forms;
type
TOnRightDlbClick = procedure(Sender:TObject)o f Object;
TRButDblClk = class( TComponent )
private
FOnRightDlbClick: TOnRightDlbClick;
protected
procedure AppMessage(var Mesg: TMsg; var Handled: Boolean);
public
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property OnRightDlbClick: TOnRightDlbClick read FOnRightDlbClick write FOnRightDlbClick;
end;
procedure Register;
implementation
constructor TRButDblClk.Create( AOwner: TComponent );
begin
inherited Create( AOwner );
Application.OnMessage := AppMessage;
end;
destructor TRButDblClk.Destroy;
begin
inherited Destroy;
end;
procedure TRButDblClk.AppMessage(var Mesg: TMsg; var Handled: Boolean);
begin
Handled := False;
if Mesg.message = WM_RBUTTONDBLCLK then
begin
if Assigned(FOnRightDlbClick) then FOnRightDlbClick(Self);
end;
end;
procedure Register;
begin
RegisterComponents('Additi onal', [TRButDblClk]);
end;
end.
- - - - - - - - - - - - - - - - - -
unit RButDblClk;
interface
uses
SysUtils, Windows, Messages, Classes, Forms;
type
TOnRightDlbClick = procedure(Sender:TObject)o
TRButDblClk = class( TComponent )
private
FOnRightDlbClick: TOnRightDlbClick;
protected
procedure AppMessage(var Mesg: TMsg; var Handled: Boolean);
public
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property OnRightDlbClick: TOnRightDlbClick read FOnRightDlbClick write FOnRightDlbClick;
end;
procedure Register;
implementation
constructor TRButDblClk.Create( AOwner: TComponent );
begin
inherited Create( AOwner );
Application.OnMessage := AppMessage;
end;
destructor TRButDblClk.Destroy;
begin
inherited Destroy;
end;
procedure TRButDblClk.AppMessage(var
begin
Handled := False;
if Mesg.message = WM_RBUTTONDBLCLK then
begin
if Assigned(FOnRightDlbClick)
end;
end;
procedure Register;
begin
RegisterComponents('Additi
end;
end.
Slick812, using Application.OnMessage in a component is unwise. Application.HookMainWindow is the way to go because it installs and handles a handler chain.
ASKER
robert : With ApplicationHookMainWindow, what happen if the db right click occurs not on the main form, but on another application's form ? and if this form is not modal ?
regards
Mike
regards
Mike
Nothing happens. Application.HookMainWindow is local to the application. It is like Application.OnMessage, only that a component should not occupy Application.OnMessage.
ASKER
robert : ok, give me just some time to have a look on your solution.
Slick812 : thanks a lot for this full comment. Even it will maybe not the best solution, I do appreciate such comments.
regards
Mike
Slick812 : thanks a lot for this full comment. Even it will maybe not the best solution, I do appreciate such comments.
regards
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi jacco !
Nice job ! It works fine, and I just had to copy/paste your example to be sure that it was what I need.
Points have been increased up to 150 for "really complete-full-working-answ er". :-)
Regards.
Mike
Nice job ! It works fine, and I just had to copy/paste your example to be sure that it was what I need.
Points have been increased up to 150 for "really complete-full-working-answ
Regards.
Mike
GL
Mike