I’m currently working on a project that involves a significant amount of hooking and is designed to operate as an overlay for an interactive product in the same way the ‘Steam Overlay‘ does.
The hooking part is actually complete. We have an ‘invisible’ WPF application that performs DLL injection, hooks DirectX, renders itself to a texture and then renders that texture on the application being hooked.

The difficulty we’re having is the latter part; getting input information intended for the overlay. As you can see in the diagram, the trivial example is a button being pushed. What I would like to do, is actually capture all input messages (WM_x) to the DirectX application and then let the WPF application decide which messages are relevant to the overlay and which aren’t.
I have managed to hook the WNDPROC of the DirectX application by using…
IntPtr _oldWindProc = GetWindowLong(MainWindowHandle, Win32Helper.GWL_WNDPROC);
WndProcDelegate _myProc = new Win32Helper.WndProc(WndProc);
SetWindowLong(MainWindowHandle, Win32Helper.GWL_WNDPROC, _myProc );
…and this seems to work well. At this point I can pass all WM_x messages back to the WPF application. But that’s where I am stuck. I have tried PostMessage and Spy++ shows the WPF window receiving the messages (and in fact setting a hook inside the WPF window reveals the same) but this doesn’t seem to work as intended. So, what am I missing? Are there certain Windows messages I should be responding to? I naively assumed it’d be as simple as having the WPF application receive a “WM_LBUTTONDOWN” at the correct location and the button would depress.
Any guidance would be greatly appreciated.
UPDATE: I might have glossed over the actual problem a bit. I want to redirect the messages to the WPF as if that was their intended destination. I have already hooked the messages and blocked them from going to the DirectX application. The question is how I can pass them on to the WPF application seamlessly.
There were too many edge reasons why this wouldn’t work as intended so I resorted to manually patching the specific events that I wanted (mouse events, basically).