WndProc,如何捕获所有按钮按下?

发布于 2024-12-04 03:52:04 字数 1278 浏览 1 评论 0原文

我正在为带有条形码阅读器的 .NET CF3.5 WM6.1 设备开发一个应用程序,并希望捕获设备上的所有按钮(F1、1、扫描仪按钮)单击。我特别感兴趣的是如何捕捉条形码按钮的按下。我写了一个小应用程序,但我能捕捉到的唯一动作就是关闭。 谁能帮我处理这段代码吗?我错过了什么?

public partial class Form1 : Form
{
    MsgHandler m_MsgHandler;
    public Form1()
    {
        InitializeComponent();
        m_MsgHandler = new MsgHandler(this);
    }
    public class MsgHandler : MessageWindow
    {
        public const int WM_CLOSE = 71;
        public const int WM_USER = 0x0400;
        public const int WM_SCANTRIGGER = WM_USER + 702;
        private Form1 m_myForm;

        public MsgHandler(Form1 form)
        {
            m_myForm = form;
        }
        protected override void WndProc(ref Message msg)
        {
            switch (msg.Msg)
            {
                case WM_SCANTRIGGER:
                   this.m_myForm.DoAction1();
                   break;
                case WM_CLOSE:
                   break;
                default:
                    this.m_myForm.DoAction2(msg.WParam.ToInt32());
                    break;
            }
        }
    }
    public void DoAction1()
    {
        MessageBox.Show("Scann btn pressed!");
    }
    public void DoAction2(int button)
    {
        MessageBox.Show(button.ToString());
    }
}

谢谢你, 卢卡斯

I am developing an application for a .NET CF3.5 WM6.1 device with a barcode reader and want to catch all buttons (F1, 1, scanner buttons) click on a device. Especially I am interested how to catch barcode button press. I wrote a tiny app, but the only action I can catch is form close.
Could anyone help me with this code? What I missed?

public partial class Form1 : Form
{
    MsgHandler m_MsgHandler;
    public Form1()
    {
        InitializeComponent();
        m_MsgHandler = new MsgHandler(this);
    }
    public class MsgHandler : MessageWindow
    {
        public const int WM_CLOSE = 71;
        public const int WM_USER = 0x0400;
        public const int WM_SCANTRIGGER = WM_USER + 702;
        private Form1 m_myForm;

        public MsgHandler(Form1 form)
        {
            m_myForm = form;
        }
        protected override void WndProc(ref Message msg)
        {
            switch (msg.Msg)
            {
                case WM_SCANTRIGGER:
                   this.m_myForm.DoAction1();
                   break;
                case WM_CLOSE:
                   break;
                default:
                    this.m_myForm.DoAction2(msg.WParam.ToInt32());
                    break;
            }
        }
    }
    public void DoAction1()
    {
        MessageBox.Show("Scann btn pressed!");
    }
    public void DoAction2(int button)
    {
        MessageBox.Show(button.ToString());
    }
}

Thank you,
Lukas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

巷雨优美回忆 2024-12-11 03:52:04

条形码阅读器的行为通常与普通键盘类似,因此无需按下特殊按钮。您只会收到按键已按下的消息,并且在输入完整代码后即可输入。

Barcode reader usually behave like normal keyboard so there is no special buttons pressed. You just get messages that keys got pressed and after whole code you get enter.

从来不烧饼 2024-12-11 03:52:04

Microsoft POS for .NET 可能会有所帮助。

Microsoft POS for .NET may be helpful.

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