How can I catch messages for all windows from one central place in my application (winforms). I need one central place in my application (e.g. programm.cs or Mainform) that can react to every Creation or alternate every showing (WM_FORMSHOW 0x18) of a Form. Forms are copntributed from other developers, AddIns, but they are activated in the default appd开发者_高级运维omain. Allthough activation in another appdomain would be an interesting case too.
the Enviroment is .Net 3.5 or 4 and c#.
thank you
You can trap windows messages by creating an IMessageFilter
, and adding it to the application via Application.AddMessageFilter
.
Inside your IMessageFilter
implementation class, you implement PreFilterMessage
, where you can look for whatever you want - it is passed a Message
that contains the same data a C-style windows message loop would get. Note that you can also add a IMessageFilter
to a specific form if you wish, as as the entire Application message loop.
精彩评论