• 大小: 316KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-15
  • 语言: C#
  • 标签: BarScan  

资源简介

c#下开发的条形码扫描源码,已经编译通过,可以运行的

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;

namespace BarCodeScan
{
    public class BarCodeHook
    {
        public delegate void BarCodeDelegate(BarCodes barCode);
        public event BarCodeDelegate BarCodeEvent;

        public struct BarCodes
        {
            public int VirtKey;      //虚拟码   
            public int ScanCode;     //扫描码   
            public string KeyName;   //键名   
            public uint AscII;       //AscII   
            public char Chr;         //字符  

            public string BarCode;   //条码信息   
            public bool IsValid;     //条码是否有效   
            public DateTime Time;    //扫描时间   
        }

        private struct EventMsg
        {
            public int message;
            public int paramL;
            public int paramH;
            public int Time;
            public int hwnd;
        }

        [DllImport(“user32.dll“ CharSet = CharSet.Auto CallingConvention = CallingConvention.StdCall)]
        private static extern int SetWindowsHookEx(int idHook HookProc lpfn IntPtr hInstance int threadId);

        [DllImport(“user32.dll“ CharSet = CharSet.Auto CallingConvention = CallingConvention.StdCall)]
        private static extern bool UnhookWindowsHookEx(int idHook);

        [DllImport(“user32.dll“ CharSet = CharSet.Auto CallingConvention = CallingConvention.StdCall)]
        private static extern int CallNextHookEx(int idHook int nCode Int32 wParam IntPtr lParam);

        [DllImport(“user32“ EntryPoint = “GetKeyNameText“)]
        private static extern int GetKeyNameText(int lParam StringBuilder lpBuffer int nSize);

        [DllImport(“user32“ EntryPoint = “GetKeyboardState“)]
        private static extern int GetKeyboardState(byte[] pbKeyState);

        [DllImport(“user32“ EntryPoint = “ToAscii“)]
        private static extern bool ToAscii(int VirtualKey int ScanCode byte[] lpKeyState ref uint lpChar int uFlags);

        delegate int HookProc(int nCode Int32 wParam IntPtr lParam);
        BarCodes barCode = new BarCodes();
        int hKeyboardHook = 0;
        string strBarCode = ““;

        private int KeyboardHookProc(int nCode Int32 wParam IntPtr lParam)
        {
            if (nCode == 0)
            {
                EventMsg msg = (EventMsg)Marshal.PtrToStructure(lParam typeof(EventMsg));

                if (wParam == 0x100)   //WM_KEYDOWN = 0x100   
                {
                    barCode.VirtKey = msg.message & 0xff; //虚拟码   
                    barCode.ScanCode = msg.paramL & 0xff; //扫描码  

                    StringBuilder strKeyName = new StringBuilder(255);
                    if (GetKeyNameText(barCode.ScanCode * 65536 strKeyName 255) > 0)
                    {
                        barCode.KeyName = strKeyName.ToString().Trim(new char[] { ‘ ‘ ‘\0‘ });
                    }
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5098  2011-04-21 12:10  BarCodeScan\BarCodeScan\BarCodeHook.cs

     文件       3443  2011-04-21 12:37  BarCodeScan\BarCodeScan\BarCodeScan.csproj

     文件      17408  2011-04-21 13:37  BarCodeScan\BarCodeScan\bin\Debug\BarCodeScan.exe

     文件      42496  2011-04-21 13:37  BarCodeScan\BarCodeScan\bin\Debug\BarCodeScan.pdb

     文件      14328  2011-04-21 13:40  BarCodeScan\BarCodeScan\bin\Debug\BarCodeScan.vshost.exe

     文件        490  2007-07-21 01:33  BarCodeScan\BarCodeScan\bin\Debug\BarCodeScan.vshost.exe.manifest

     文件     574976  2008-06-02 00:00  BarCodeScan\BarCodeScan\bin\Debug\user32.dll

     文件      12087  2011-04-21 12:31  BarCodeScan\BarCodeScan\Code39.cs

     文件        642  2011-04-21 13:40  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.csproj.FileListAbsolute.txt

     文件        849  2011-04-21 13:35  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.csproj.GenerateResource.Cache

     文件      17408  2011-04-21 13:37  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.exe

     文件      42496  2011-04-21 13:37  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.pdb

     文件        180  2011-04-21 13:13  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.Properties.Resources.resources

     文件        180  2011-04-21 13:35  BarCodeScan\BarCodeScan\obj\Debug\BarCodeScan.StartUp.resources

     文件        474  2011-04-21 11:28  BarCodeScan\BarCodeScan\Program.cs

     文件       1378  2011-04-21 11:27  BarCodeScan\BarCodeScan\Properties\AssemblyInfo.cs

     文件       2872  2011-04-21 11:27  BarCodeScan\BarCodeScan\Properties\Resources.Designer.cs

     文件       5612  2011-04-21 11:27  BarCodeScan\BarCodeScan\Properties\Resources.resx

     文件       1096  2011-04-21 11:27  BarCodeScan\BarCodeScan\Properties\Settings.Designer.cs

     文件        249  2011-04-21 11:27  BarCodeScan\BarCodeScan\Properties\Settings.settings

     文件       4238  2011-04-21 17:04  BarCodeScan\BarCodeScan\StartUp.cs

     文件       4843  2011-04-21 13:33  BarCodeScan\BarCodeScan\StartUp.Designer.cs

     文件       5814  2011-04-21 13:33  BarCodeScan\BarCodeScan\StartUp.resx

     文件        923  2011-04-21 11:54  BarCodeScan\BarCodeScan.sln

    ..A..H.     37888  2011-04-21 13:51  BarCodeScan\BarCodeScan.suo

     目录          0  2011-04-21 11:28  BarCodeScan\BarCodeScan\obj\Debug\Refactor

     目录          0  2011-04-21 11:27  BarCodeScan\BarCodeScan\obj\Debug\TempPE

     目录          0  2011-04-21 12:57  BarCodeScan\BarCodeScan\bin\Debug

     目录          0  2011-04-21 13:37  BarCodeScan\BarCodeScan\obj\Debug

     目录          0  2011-04-21 11:28  BarCodeScan\BarCodeScan\bin

............此处省略7个文件信息

评论

共有 条评论

相关资源