7

I have a small question hoping someone will help me. Is there any way to hook into other applications WNDPROC?

The situation is that I want to insert a menu in the other app menubar and I want to define the commands for every menu item.

I was able to insert the menu with menu items using some Win32 API functions (user32.dll), but I can't set the commands of that menu item so that it actually does something if clicked.

With some googling, I got some information about wndprocess, and I should intercept the ID Command sent and trigger some function, but I'm stuck.

Can anyone help me?

Matze
  • 5,100
  • 6
  • 46
  • 69
K7rim
  • 147
  • 10
  • What do you have so far? – Niklas B. Mar 20 '12 at 22:02
  • just the menus created and inserted,idon't know to override the app wndprpc – K7rim Mar 20 '12 at 22:08
  • 2
    Window hooks are your friend, check `SetWindowsHookEx` on MSDN. The bigger problem is to get the code into the remote process, since you mention Python. A window hook such as this one would generally cause a DLL with the hook function to be loaded into the remote process and to be run from there. – 0xC0000022L Mar 20 '12 at 22:09
  • 1
    Yes, an injected DLL would definitely be the way to go. If you really want, you can make that DLL bind to a socket, so you can connect to it from Python and communicate with it. – Niklas B. Mar 20 '12 at 22:11
  • 1
    thank you for ur responses. this seems way over my head!,is there any way to create menus other than injecting dll stuff?! – K7rim Mar 20 '12 at 22:28
  • @K7rim: Does the application you want to extend have a system for plugins? That would probably be an easier way to work with it. – Roland Smith May 10 '12 at 22:41

1 Answers1

2

You are going about this the wrong way. If you think about it, you'll realize that responding to menu events with your custom "actions" must require some code to run in the process that you're targeting. This means you'll need to inject code into the other process in order to achieve what you want.

Since you're going to need to inject code anyway, I strongly suggest you look at DLL-injecting into the other process (search "Dll Injection example"). This will bootstrap your code into the other process, and you can construct your menu there.

This also has the advantage that the foreign app won't be reliant on your app being responsive - it'll all be in-process.

SecurityMatt
  • 6,593
  • 1
  • 22
  • 28