Solved

Custom Events

Posted on 2001-08-18
7
832 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

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 34

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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