WndProc,如何捕获所有按钮按下?
我正在为带有条形码阅读器的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
条形码阅读器的行为通常与普通键盘类似,因此无需按下特殊按钮。您只会收到按键已按下的消息,并且在输入完整代码后即可输入。
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.
Microsoft POS for .NET 可能会有所帮助。
Microsoft POS for .NET may be helpful.