Reputation: 23662
I'd like to use the functionality of System.Windows.Forms.Application.AddMessageFilter but my target application does not use Windows Forms. This functionality adds a filter to monitor Windows messages as they are routed. If anyone knows how this works, I wouldn't mind writing my own code to perform the same function.
SetWindowLong with GWL_WNDPROC only affects received messages and I'd like to affect sent messages. System.Windows.Forms.Application is static but calling AddMessageFilter with an IMessageFilter that throws an exception does not work.
Upvotes: 2
Views: 1011
Reputation: 69262
You can use a message hook to achieve what you want. In fact, a message hook is far more powerful than IMessageFilter because there are other kinds of hooks other than just windows messages sent to a window handle. For example you can hook system-wide keypresses or mouse movements.
See this article for more information
http://msdn.microsoft.com/en-us/magazine/cc188966.aspx
Upvotes: 2