Listening to OS messages in C#
Is there any methods in C# similar to WndProc method to listen to the OS messages.I cant use WndProc because,my class is neither Form nor Inherited from Control(Its DLL)
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
// listen os messages
// Ueye Message
case uEye.IS_UEYE_MESSAGE:
//fetch frame
break;
}
base.WndPr开发者_Python百科oc(ref m);
}
WMI will do if you want to listen for specific messages. I once had a project (see comment on question) that listened for removeable USB drives and WMI worked just fine.
You can use interop as well but I find it messy but YMMV.
The standard approach to receiving windows messages in the absence of a visible window is to create a non-visible window to receive messages.
You should use Windows.Interop
to have access to Win API
Check this: http://social.msdn.microsoft.com/Forums/en-IE/winforms/thread/b44f06fb-fc4a-4fac-87cd-48b2953ea5fa
It seems to be possible to override WndProc, but I haven't tried it myself!
If you have a Form (visible or otherwise), look at Form.WndProc
.
If not, you could try using Application.AddMessageFilter to add a message filter to monitor Windows messages.
精彩评论