Question

I'm writing a program that inserts additional options in window title context menu of windows others than that of my own process. Here is how I found out how to do this: Adding a custom context menu item to Windows Form title bar. I just need to have a valid IntPtr handle to that window. I tested it and it works. Second part is making my application (not the other process) to do something when user selects that option from context menu from the other process' window. I don't see any straight forward way to detect this. I know that I can setup hooks so my program listens to all windows messages on my machine (WM_SYSCOMMAND from window i'm interested in) but from what I've seen this solution is pretty complex and I wonder if there is any way to assign some delegate or something to that menu option ?

Was it helpful?

Solution

The messages are sent to a window in the target process. So you'll need to get your code running in that process. That's going to involve DLL injection and so you'll need to write native code rather than C#. You'll need to inject a DLL and subclass the window that receives the messages so that your code can have first shot at them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top