예제 #1
0
        protected IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (DataSource.SourceId.Id == 0)
            {
                handled = false;
                return(IntPtr.Zero);
            }

            int pos = User32Native.GetMessagePos();

            WindowsMessage message = new WindowsMessage();

            message.hwnd    = hwnd;
            message.message = msg;
            message.wParam  = wParam;
            message.lParam  = lParam;
            message.time    = User32Native.GetMessageTime();
            message.x       = (short)pos;
            message.y       = (short)(pos >> 16);

            Marshal.StructureToPtr(message, _eventMessage.EventPtr, false);
            _eventMessage.Message = 0;

            TwainResult result = Twain32Native.DsEvent(
                ApplicationId,
                DataSource.SourceId,
                DataGroup.Control,
                DataArgumentType.Event,
                Message.ProcessEvent,
                ref _eventMessage);

            if (result == TwainResult.NotDSEvent)
            {
                handled = false;
                return(IntPtr.Zero);
            }

            switch (_eventMessage.Message)
            {
            case Message.XFerReady:
                Exception exception = null;
                try
                {
                    TransferPictures();
                }
                catch (Exception e)
                {
                    exception = e;
                }
                CloseDsAndCompleteScanning(exception);
                break;

            case Message.CloseDS:
            case Message.CloseDSOK:
            case Message.CloseDSReq:
                CloseDsAndCompleteScanning(null);
                break;

            case Message.DeviceEvent:
                break;

            default:
                break;
            }

            handled = true;
            return(IntPtr.Zero);
        }
예제 #2
0
        protected IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (DataSource.SourceId.Id == 0)
            {
                handled = false;
                return(IntPtr.Zero);
            }

            int pos = User32Native.GetMessagePos();

            WindowsMessage message = new WindowsMessage();

            message.hwnd    = hwnd;
            message.message = msg;
            message.wParam  = wParam;
            message.lParam  = lParam;
            message.time    = User32Native.GetMessageTime();
            message.x       = (short)pos;
            message.y       = (short)(pos >> 16);

            Marshal.StructureToPtr(message, _eventMessage.EventPtr, false);
            _eventMessage.Message = 0;

            TwainResult result = Twain32Native.DsEvent(
                ApplicationId,
                DataSource.SourceId,
                DataGroup.Control,
                DataArgumentType.Event,
                Message.ProcessEvent,
                ref _eventMessage);

            if (result == TwainResult.NotDSEvent)
            {
                handled = false;
                return(IntPtr.Zero);
            }

            switch (_eventMessage.Message)
            {
            case Message.XFerReady:
                IList <IntPtr> imagePointers = TransferPictures();

                foreach (IntPtr image in imagePointers)
                {
                    using (var renderer = new BitmapRenderer(image))
                    {
                        Images.Add(renderer.RenderToBitmap());
                    }
                }

                EndingScan();
                DataSource.Close();

                ScanningComplete(this, EventArgs.Empty);
                break;

            case Message.CloseDS:
                EndingScan();
                DataSource.Close();
                break;

            case Message.CloseDSOK:
                EndingScan();
                DataSource.Close();
                break;

            case Message.DeviceEvent:
                break;
            }

            handled = true;
            return(IntPtr.Zero);
        }