Solved

Custom Events

Posted on 2001-08-18
7
829 Views
Last Modified: 2011-09-20
How do I create a custom mouse event for a component? I want to incorporate Macromedia Flash into my application but want to completely disable the right-click popups from appearing. I'm currently using Delphi 4.

Please include sample codes as well if there's a solution. Many Thanks.
0
Comment
Question by:NitroBlaze
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6400110
Hi NitroBlaze,

here is the way how to hook mouse clicks application wide.

var
  Hook: Integer;

procedure MouseHook(ID, WParam, LParam: Integer); stdcall;
begin
  if (WParam = WM_RBUTTONDOWN) or
    (WParam = WM_RBUTTONUP) then
  begin
    // here is your code to process right button up-down
  else
    CallNextHookEx(Hook, ID, WParam, LParam);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Hook := SetWindowsHookEx(WH_MOUSE, @MouseHook, 0, MainThreadID);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnhookWindowsHookEx(Hook);
end;

-------
Igor
0
 

Author Comment

by:NitroBlaze
ID: 6400239
I appreciate your help but I would like only the Flash component to have the context menus disabled because my program does incorporate right-click functions. Any way of going about this?
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6400305
Hi NitroBlaze,

here is another version of MouseHook function. It prevents show popup menu for controls with "TMemo" classname.

function MouseHook(ID, WParam, LParam: Integer): Integer; stdcall;
var
  L: ^TMouseHookStruct;
  W: TWinControl;
begin
  Result := -1;
  if ID < 0 then
    Result := CallNextHookEx(Hook, ID, WParam, LParam)
  else
  begin
    if (WParam = WM_RBUTTONDOWN) or
      (WParam = WM_RBUTTONUP) then
    begin
      L := pointer(LParam);
      W := FindVCLWindow(L^.pt);
      if (W <> nil) and (W.ClassName <> 'TMemo') then
          Result := CallNextHookEx(Hook, ID, WParam, LParam);
    end
    else
      Result := CallNextHookEx(Hook, ID, WParam, LParam);
  end;
end;
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 33

Expert Comment

by:Slick812
ID: 6402838
if you just want to prevent a right mouse click on a single control like Macromedia Flash , , then you can use the Application.OnMessage to get windows system messages BEFORE the are sent to the control, you have to declare the Application.OnMessage := AppMessage; in your FormCreate and then use Handel to identify your control and set Handled to True

procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;

procedure TMainForm.AppMessage(var Mssg: TMsg; var Handled: Boolean);
begin
Handled := False;

if ((Mssg.message = WM_RBUTTONDOWN) or
     (Mssg.message = WM_RBUTTONUP)) and (Mssg.hWnd = MacroFlash1.Handle) then
Handled := True;

end;
0
 

Author Comment

by:NitroBlaze
ID: 6403074
Both are good solutions. I will provide points also to the other party.
0
 

Author Comment

by:NitroBlaze
ID: 6403083
BTW - off the record, you guys can recommend any good books to on Delphi programming? The book should be nothing about the basics and shouldn't be focused on versions...

thanks if you can recommend one.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6404349
if you want more than basics the Sams publishing  "Unleashed" (like Delphi4 Unleashed) series has some unusual non-basic subjects. The QUE publishing "Using Delphi" is another Non-beginers series of books. The Sams Borland-Press books "Delphi Developers Guide" is an advanced guide, but they may not publish those any more.

a side note - The SetWindowsHookEx(WH_MOUSE,  may best be used if you need a mouse event for many controls, right click on all or most of the controls, (delphi uses the mouseHook for their "Hints") but if you just need one or two controls, using the windows messages "Directly" in the apps Windows message responce may be better.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question