Link to home
Start Free TrialLog in
Avatar of raheelasadkhan
raheelasadkhanFlag for Pakistan

asked on

Detecting mouse clicks and keyboard events on precompiled activeX controls

Hello,

I am developing a WinForms application (.NET 1.1) that uses an ActiveX control. This control does not expose a Click event.

My objective it to get notified whenever the user clicks the left mouse button on an ActiveX control on my form. The ActiveX control is precompiled so I cannot trap the event from within it. I need to trap it on the form where it's hosted.

Any ideas? I would gladly settle for a high or low level solution alike. Have working knowledge of Win32 API.

Thanks,

Khan
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

You could install a low level mouse hook using WH_MOUSE_LL as in this example:
http://www.codeproject.com/csharp/globalhook.asp

Then whenever a click is trapped you can see if your application is in focus and then check the coordinates to see if they are over your ActiveX control.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raheelasadkhan

ASKER

Idle_Mind: Thanks! Simple and elegant solution.

Before seeing your solution, I already found another one but since the delay in reading was on my part, I'm accepting your entry.

My solution was very similar; overriding the WndProc function to trap the WM_PARENTNOTIFY message since the main form recieves this message whenever WM_LBUTTONDOWN (among others) occurs. If you like, you can see the source at: (https://www.experts-exchange.com/questions/21854816/HTMLDocument-events-in-C.html)

Although your solution looks to be about the same, I am not sure what a message filter is by concept. Is it simply a .NET interface to Win32 message? If not, which approach is better?

Thanks again.
See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsimessagefilterclasstopic.asp

    "This interface allows an application to capture a message before it is dispatched to a control or form"

The key phrase here is "before it is dispatched to...".  IMessageFilter allows you to basically preview all messages intended for your application.  You can then decide to let them thru or "filter" certain ones out so they are never received.

Your approach differs in that you are notified after the event as occurred.
Got it. Thanks