Receive messages of other window

542 views Asked by At

What I'm trying to do: receive messages of other process window (Spy++).

For example: I opened new notepad window: https://i.stack.imgur.com/vNg6h.png

And then I moved the mouse over the notepad window, the windows will send this message to the notepad window (or to the main window child window/s):

WM_MOUSEMOVE xPos=100,yPos=200

I want to receive this message exactly when then mouse event is happening (by event or while loop) (probably while loop with Application.doEvents() and Threading.Thread.Sleep(1)).

What I have tried:

Good example is better than explanation for me. :)

2

There are 2 answers

0
David Heffernan On BEST ANSWER

The hooks that you need for this are WH_CALLWNDPROC and WH_GETMESSAGE. And these require DLL injection. You cannot inject managed code and so you will need to use unmanaged code for the hooking. You can then get your unmanaged injected DLL to communicate back to your C# application, but you will have to concede defeat on your attempts to write the hooking code in C#.

0
WAKU On

You need to look at the HOOK. That's how SPY++ works. However, .Net is not very suitable for this, because you have to use a lot of WIN32 API functions.