在 C# 中监听操作系统消息
C# 中是否有类似于 WndProc 方法的方法来监听操作系统消息。我不能使用 WndProc,因为我的类既不是 Form,也不是从 Control(其 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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您愿意,WMI 就可以了收听特定消息。
我曾经有一个项目(请参阅问题评论),它监听可移动 USB 驱动器,并且 WMI 工作得很好。
你也可以使用互操作,但我发现它很混乱,但是YMMV。
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.
您应该使用 Windows.Interop
来访问 Win应用程序编程接口
You should use Windows.Interop
to have access to Win API
检查这个: http:// Social.msdn.microsoft.com/Forums/en-IE/winforms/thread/b44f06fb-fc4a-4fac-87cd-48b2953ea5fa
似乎可以重写WndProc,但我自己没有尝试过!
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!
如果您有表单(可见或其他形式),请查看
Form.WndProc
。如果没有,您可以尝试使用 Application.AddMessageFilter< /a> 添加消息过滤器来监视 Windows 消息。
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.