在 C# 中监听操作系统消息

发布于 2024-10-31 00:33:25 字数 425 浏览 9 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏雨凉 2024-11-07 00:33:25

如果您愿意,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.

蛮可爱 2024-11-07 00:33:25

在没有可见窗口的情况下接收窗口消息的标准方法是创建一个不可见窗口来接收消息。

The standard approach to receiving windows messages in the absence of a visible window is to create a non-visible window to receive messages.

蓝海 2024-11-07 00:33:25

您应该使用 Windows.Interop

来访问 Win应用程序编程接口

You should use Windows.Interop

to have access to Win API

瑶笙 2024-11-07 00:33:25

检查这个: 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!

歌入人心 2024-11-07 00:33:25

如果您有表单(可见或其他形式),请查看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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文