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;
开发者_如何学Python 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
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 may be helpful.
精彩评论