/// <summary>
        /// 设置下拉列表的当前值
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="capInfo"></param>
        /// <returns></returns>
        private bool SetCurrentValueOfComboBox(ComboBox comboBox, CapInfo capInfo)
        {
            if (capInfo.CurrentIntStr == null)
            {
                return(false);
            }
            string enumStr    = twSession.ConvertIntStringToEnumString(capInfo.CapId, capInfo.CurrentIntStr);
            string currentStr = null;
            int    i          = comboBox.Items.Count - 1;

            for (; i >= 0; i--)
            {
                string tempStr = (comboBox.Items[i] as ComboBoxItem).Content.ToString();
                if (tempStr == enumStr)
                {
                    comboBox.SelectedIndex = i;
                    currentStr             = tempStr;
                    break;
                }
            }
            if (i < 0)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 系统消息处理函数
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="handled"></param>
        private void MessageFilter(ref System.Windows.Interop.MSG msg, ref bool handled)
        {
            //1:让TWAIN进行消息处理
            TwainCommand cmd = twSession.PassMessageWPF(ref msg);

            messageLogger.Debug("TWAIN 信息 = " + cmd + ":" + DateTime.Now);

            if (cmd == TwainCommand.Not || cmd == TwainCommand.Null) // 非数据源消息
            {
                handled = false;                                     // 消息未处理,由窗口过程处理
                return;
            }

            //2:进行消息处理
            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                configFlag = false;
                EndingScan();
                twSession.DisableDS();
                break;
            }

            case TwainCommand.CloseOk:
            {
                configFlag = true;
                EndingScan();
                twSession.DisableDS();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            //扫描仪传输就绪函数
            case TwainCommand.TransferReady:
            {
                loadAndUnloadLogger.Debug("TWAIN 信息 = TransferReady " + DateTime.Now);
                ScanImageViewer scanViewer = null;
                try
                {
                    if (ShowProgress)
                    {
                        //方式一:启动文件传输,弹出进度提示对话框
                        //获得文件格式
                        CapInfo capInfo;
                        capInfo = twSession.GetScannerCap(TwCap.ICAP_IMAGEFILEFORMAT);
                        string       intStr     = capInfo.CurrentIntStr;
                        string       enumStr    = twSession.ConvertIntStringToEnumString(TwCap.ICAP_IMAGEFILEFORMAT, intStr);
                        TwFileFormat fileFormat = (TwFileFormat)Enum.Parse(typeof(TwFileFormat), enumStr);

                        //获取分辨率
                        capInfo = twSession.GetScannerCap(TwCap.ICAP_XRESOLUTION);
                        Int32 resolution = Int32.Parse(capInfo.CurrentIntStr);

                        // 获得空白页检测阈值
                        capInfo = twSession.GetScannerCap(TwCap.ICAP_AUTODISCARDBLANKPAGES);
                        intStr  = capInfo.CurrentIntStr;
                        int blankImageSizeThreshold = 0;
                        if (!Int32.TryParse(intStr, out blankImageSizeThreshold))
                        {
                            blankImageSizeThreshold = 0;
                        }
                        scanViewer = new ScanImageViewer(twSession, userConfig.MaxSize, blankImageSizeThreshold, resolution, fileFormat); //生成显示控件对象
                        scanViewer.StartTransfer();                                                                                       //开始图像传输
                        scanViewer.ShowDialog();                                                                                          //展示显示控件
                        scanResultList = scanViewer.ScanFileNames;                                                                        //获取文件传输过程中的列表
                    }
                    else
                    {
                        //方式二:设置鼠标为等待状态,在相同线程中启动文件传输
                        Mouse.OverrideCursor = Cursors.Wait;
                        TransferFiles();
                    }
                    //发出扫描完成事件
                    logger.Debug("扫描完成 :" + DateTime.Now);
                    RoutedEventArgs scanArgs = new RoutedEventArgs(ScanCompletedEvent);
                    RaiseEvent(scanArgs);
                    break;
                }
                catch (Exception e)
                {
                    logger.Error("在MessageFilter中发生异常,异常信息; " + e.Message);
                }
                finally
                {
                    if (scanViewer != null)
                    {
                        logger.Debug("关闭扫描仪。");
                        scanViewer.Close();
                    }
                    //结束扫描
                    logger.Debug("结束扫描,使DS变为非使能状态。");
                    EndingScan();
                    twSession.DisableDS();
                    if (!ShowProgress)
                    {
                        //将鼠标复位
                        Mouse.OverrideCursor = null;
                    }
                }
                break;
            }

            default:
                break;
            }
            handled = true;
        }