| 
 | 
 
 
 楼主 |
发表于 2013-4-9 13:58:58
|
显示全部楼层
 
 
 
[code=csharp]public partial class CheckTicket2WM : Form 
    { 
        public CheckTicket2WM() 
        { 
            InitializeComponent(); 
        } 
        //设备状态 
        public Boolean state = true; 
 
        protected override void DefWndProc(ref Message msg) 
        { 
            Console.WriteLine("消息句柄MSG:" + msg.Msg); 
            if (msg.Msg == 123) 
            { 
                IntPtr wp = new IntPtr((int)msg.WParam); 
 
                byte[] wpbuf = new byte[((int)msg.LParam)]; 
                Marshal.Copy(wp, wpbuf, 0, ((int)msg.LParam)); 
 
                string strBC = System.Text.Encoding.GetEncoding("UTF-8").GetString(wpbuf, 0, ((int)msg.LParam)); 
 
                string result = strBC.Trim(); 
 
                this.getInfo(result); 
            } 
            else 
            { 
                base.DefWndProc(ref msg); 
 
            } 
 
        } 
      
        private void btnRestart_Click(object sender, EventArgs e) 
        { 
            Dll_Camera.ReleaseDevice(); 
            Dll_Camera.StartDevice(); 
        } 
 
        private void pictureBox3_Click(object sender, EventArgs e) 
        { 
            this.getInfo(this.txtNo.Text); 
            this.txtNo.Text = ""; 
            this.txtNo.Focus(); 
        } 
 
        private void pictureBox4_Click(object sender, EventArgs e) 
        { 
            this.txtNo.Text = ""; 
            this.txtNo.Focus(); 
        } 
 
        private void CheckTicket2WM_Load(object sender, EventArgs e) 
        { 
            //通过消息得到解码信息 
            Dll_Camera.GetAppHandle(this.Handle); 
 
            this.timer1.Enabled = true; 
            this.timer1.Interval = 10; 
            this.timer2.Enabled = true; 
            this.timer2.Interval = 10; 
        } 
 
        private void CheckTicket2WM_Closing(object sender, FormClosingEventArgs e) 
        { 
            DeviceUtils.releaseDevice(); 
        } 
 
        private void timer1_Tick(object sender, EventArgs e) 
        { 
            int result = Dll_Camera.GetDevice(); 
            if (result == 1) 
            { 
                if (!DeviceUtils.started) 
                { 
                    state = true; 
                    this.timer2.Enabled = true; 
                    this.timer2.Interval = 10; 
                    DeviceUtils.startDevice(); 
                } 
            } 
            else 
            { 
                state = false; 
                DeviceUtils.started = false; 
 
            } 
 
        } 
 
        private void timer2_Tick(object sender, EventArgs e) 
        { 
            int findr =  Dll_Camera.GetDevice(); 
 
            if (findr == -1){ 
                DeviceUtils.started = false; 
                Dll_Camera.ReleaseLostDevice(); 
            } 
 
 
            if (!DeviceUtils.started) 
            { 
                this.timer2.Enabled = false; 
                Dll_Camera.ReleaseDevice(); 
                MessageBox.Show("设备连接已断开!"); 
            } 
        } 
    }[/code] |   
 
 
 
 |