Solved

Custom Events

Posted on 2001-08-18
7
831 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
Industry Leaders: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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