Solved

Custom Events

Posted on 2001-08-18
7
826 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now