Exemplo n.º 1
0
        public Principal(string direccion)
        {
            _dir = direccion;

            tw = new TwainLib.Twain();
            tw.Init(this.Handle);
        }
Exemplo n.º 2
0
        public Principal()
        {
            _dir = System.IO.Path.GetTempPath() + "\\";

            tw = new TwainLib.Twain();
            tw.Init(this.Handle);
        }
Exemplo n.º 3
0
 public void Finish()
 {
     this.CloseSrc();
     if (this.appid.Id != IntPtr.Zero)
     {
         TwRC twRC = Twain.DSMparent(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref this.hwnd);
     }
     this.appid.Id = IntPtr.Zero;
 }
Exemplo n.º 4
0
 public void CloseSrc()
 {
     if (this.srcds.Id != IntPtr.Zero)
     {
         TwUserInterface guif = new TwUserInterface();
         TwRC            twRC = Twain.DSuserif(this.appid, this.srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif);
         twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, this.srcds);
     }
 }
Exemplo n.º 5
0
        public TwCapability(TwCap cap, short sval)
        {
            Cap     = (short)cap;
            ConType = (short)TwOn.One;
            Handle  = Twain.GlobalAlloc(0x42, 6);
            IntPtr pv = Twain.GlobalLock(Handle);

            Marshal.WriteInt16(pv, 0, (short)TwType.Int16);
            Marshal.WriteInt32(pv, 2, (int)sval);
            Twain.GlobalUnlock(Handle);
        }
Exemplo n.º 6
0
        public TwCapability(TwCap cap, short sval, TwType twType)
        {
            this.Cap     = (short)cap;
            this.ConType = 5;
            this.Handle  = Twain.GlobalAlloc(66, 6);
            IntPtr ptr = Twain.GlobalLock(this.Handle);

            Marshal.WriteInt16(ptr, 0, (short)twType);
            Marshal.WriteInt32(ptr, 2, (int)sval);
            Twain.GlobalUnlock(this.Handle);
        }
Exemplo n.º 7
0
        public void Acquire()
        {
            this.CloseSrc();
            if (this.appid.Id == IntPtr.Zero)
            {
                this.Init(this.hwnd);
                if (this.appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }
            TwRC twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, this.srcds);

            if (twRC == TwRC.Success)
            {
                TwCapability capa = new TwCapability(TwCap.IPixelType, 0, TwType.UInt16);
                twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa);
                if (twRC != TwRC.Success)
                {
                    this.CloseSrc();
                }
                else
                {
                    TwCapability capa2 = new TwCapability(TwCap.RESOLUTION, 200, TwType.Fix32);
                    twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa2);
                    if (twRC != TwRC.Success)
                    {
                        this.CloseSrc();
                    }
                    else
                    {
                        TwCapability capa3 = new TwCapability(TwCap.XferCount, 1, TwType.Int16);
                        twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa3);
                        if (twRC != TwRC.Success)
                        {
                            this.CloseSrc();
                        }
                        else
                        {
                            TwUserInterface twUserInterface = new TwUserInterface();
                            twUserInterface.ShowUI     = 1;
                            twUserInterface.ModalUI    = 1;
                            twUserInterface.ParentHand = this.hwnd;
                            twRC = Twain.DSuserif(this.appid, this.srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, twUserInterface);
                            if (twRC != TwRC.Success)
                            {
                                this.CloseSrc();
                            }
                        }
                    }
                }
            }
        }
        /*
         * public TwCapability(TwCap cap, short sval)
         * {
         *  Cap = (short)cap;
         *  ConType = (short)TwOn.One;
         *  Handle = Twain.GlobalAlloc(0x42, 6);
         *  IntPtr pv = Twain.GlobalLock(Handle);
         *  Marshal.WriteInt16(pv, 0, (short)TwType.Int16);
         *  Marshal.WriteInt32(pv, 2, (int)sval);
         *  Twain.GlobalUnlock(Handle);
         * }
         */
        public TwCapability(TwCap cap, TwFix32 val)
        {
            Cap     = (short)cap;
            ConType = (short)TwOn.One;
            Handle  = Twain.GlobalAlloc(0x42, 6);
            IntPtr pv = Twain.GlobalLock(Handle);

            Marshal.WriteInt16(pv, 0, (short)TwType.UInt16);
            Marshal.WriteInt32(pv, 2, (int)val.Whole);
            Marshal.WriteInt64(pv, 4, (long)val.Whole);
            Twain.GlobalUnlock(Handle);
        }
Exemplo n.º 9
0
 public void Select()
 {
     this.CloseSrc();
     if (this.appid.Id == IntPtr.Zero)
     {
         this.Init(this.hwnd);
         if (this.appid.Id == IntPtr.Zero)
         {
             return;
         }
     }
     TwRC twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.UserSelect, this.srcds);
 }
Exemplo n.º 10
0
        public TwainCommand PassMessage(ref Message m)
        {
            TwainCommand result;

            if (this.srcds.Id == IntPtr.Zero)
            {
                result = TwainCommand.Not;
            }
            else
            {
                int messagePos = Twain.GetMessagePos();
                this.winmsg.hwnd    = m.HWnd;
                this.winmsg.message = m.Msg;
                this.winmsg.wParam  = m.WParam;
                this.winmsg.lParam  = m.LParam;
                this.winmsg.time    = Twain.GetMessageTime();
                this.winmsg.x       = (int)((short)messagePos);
                this.winmsg.y       = (int)((short)(messagePos >> 16));
                Marshal.StructureToPtr(this.winmsg, this.evtmsg.EventPtr, false);
                this.evtmsg.Message = 0;
                TwRC twRC = Twain.DSevent(this.appid, this.srcds, TwDG.Control, TwDAT.Event, TwMSG.ProcessEvent, ref this.evtmsg);
                if (twRC == TwRC.NotDSEvent)
                {
                    result = TwainCommand.Not;
                }
                else if (this.evtmsg.Message == 257)
                {
                    result = TwainCommand.TransferReady;
                }
                else if (this.evtmsg.Message == 258)
                {
                    result = TwainCommand.CloseRequest;
                }
                else if (this.evtmsg.Message == 259)
                {
                    result = TwainCommand.CloseOk;
                }
                else if (this.evtmsg.Message == 260)
                {
                    result = TwainCommand.DeviceEvent;
                }
                else
                {
                    result = TwainCommand.Null;
                }
            }
            return(result);
        }
Exemplo n.º 11
0
        public void Init(IntPtr hwndp)
        {
            this.Finish();
            TwRC twRC = Twain.DSMparent(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (twRC == TwRC.Success)
            {
                twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.UserSelect, this.srcds);
                if (twRC == TwRC.Success)
                {
                    this.hwnd = hwndp;
                }
                else
                {
                    twRC = Twain.DSMparent(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                }
            }
            TwIdentity twIdentity = this.srcds;
        }
Exemplo n.º 12
0
        public void Acquire2()
        {
            this.CloseSrc();
            if (this.appid.Id == IntPtr.Zero)
            {
                this.Init(this.hwnd);
                if (this.appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }
            TwRC twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, this.srcds);

            if (twRC == TwRC.Success)
            {
                TwCapability capa = new TwCapability(TwCap.XferCount, 1, TwType.Int16);
                twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa);
                if (twRC != TwRC.Success)
                {
                    this.CloseSrc();
                }
            }
        }
Exemplo n.º 13
0
        public ArrayList TransferPictures()
        {
            ArrayList arrayList = new ArrayList();
            ArrayList result;

            if (this.srcds.Id == IntPtr.Zero)
            {
                result = arrayList;
            }
            else
            {
                IntPtr         zero           = IntPtr.Zero;
                TwPendingXfers twPendingXfers = new TwPendingXfers();
                TwRC           twRC;
                while (true)
                {
                    twPendingXfers.Count = 0;
                    zero = IntPtr.Zero;
                    TwImageInfo imginf = new TwImageInfo();
                    twRC = Twain.DSiinf(this.appid, this.srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, imginf);
                    if (twRC != TwRC.Success)
                    {
                        break;
                    }
                    twRC = Twain.DSixfer(this.appid, this.srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref zero);
                    if (twRC != TwRC.XferDone)
                    {
                        goto Block_3;
                    }
                    twRC = Twain.DSpxfer(this.appid, this.srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, twPendingXfers);
                    if (twRC != TwRC.Success)
                    {
                        goto Block_4;
                    }
                    arrayList.Add(zero);
                    if (this.ScanedImage != null)
                    {
                        this.ScanedImage(zero, new ImageEvent());
                    }
                    if (twPendingXfers.Count == 0)
                    {
                        goto Block_6;
                    }
                }
                result = arrayList;
                return(result);

Block_3:
                result = arrayList;
                return(result);

Block_4:
                result = arrayList;
                return(result);

Block_6:
                twRC   = Twain.DSpxfer(this.appid, this.srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, twPendingXfers);
                result = arrayList;
            }
            return(result);
        }
Exemplo n.º 14
0
 public TwainSource(IntPtr hwndp)
 {
     _twain = new Twain();
     _twain.Init(hwndp);
 }
Exemplo n.º 15
0
 public MainFrame()
 {
     InitializeComponent();
     tw = new Twain();
     tw.Init( this.Handle );
 }
        private int _twainCommandNullCount = 0; // hack: TwainCommand.Null is sended continuously after TWAIN device is not available or when once preview is done

        #endregion Fields

        #region Constructors

        public TwainSource(IntPtr hwndp)
        {
            _twain = new Twain();
            _twain.Init(hwndp);
        }