问题
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.WndProc(ref m);
}
回答1:
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.
回答2:
The standard approach to receiving windows messages in the absence of a visible window is to create a non-visible window to receive messages.
回答3:
You should use Windows.Interop
to have access to Win API
回答4:
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!
回答5:
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.
来源:https://stackoverflow.com/questions/5591371/listening-to-os-messages-in-c-sharp