Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Custom Events

Posted on 2001-08-18
7
Medium Priority
?
837 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 300 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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