开发者

How to centrally monitor messages sent to application or winform

开发者 https://www.devze.com 2023-01-26 03:07 出处:网络
How can I catchmessages 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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消