예제 #1
0
        public void Finish()
        {
            twainDefs.TwRC rc = 0;
            CloseSrc();

            if (appid.Id != IntPtr.Zero)
            {
                rc = DSMparent(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Parent, twainDefs.TwMSG.CloseDSM, ref hwnd);
            }
            appid.Id = IntPtr.Zero;
        }
예제 #2
0
        public void Select()
        {
            twainDefs.TwRC rc = 0;
            CloseSrc();

            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);
                if (appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }

            rc = DSMident(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Identity, twainDefs.TwMSG.UserSelect, srcds);
        }
예제 #3
0
        public ArrayList TransferPictures()
        {
            ArrayList pics = new ArrayList();

            if (srcds.Id == IntPtr.Zero)
            {
                return(pics);
            }

            twainDefs.TwRC rc      = 0;
            IntPtr         hbitmap = IntPtr.Zero;

            twainDefs.TwPendingXfers pxfr = new twainDefs.TwPendingXfers();

            do
            {
                pxfr.Count = 0;
                hbitmap    = IntPtr.Zero;

                twainDefs.TwImageInfo iinf = new twainDefs.TwImageInfo();
                rc = DSiinf(appid, srcds, twainDefs.TwDG.Image, twainDefs.TwDAT.ImageInfo, twainDefs.TwMSG.Get, iinf);
                if (rc != twainDefs.TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSixfer(appid, srcds, twainDefs.TwDG.Image, twainDefs.TwDAT.ImageNativeXfer, twainDefs.TwMSG.Get, ref hbitmap);
                if (rc != twainDefs.TwRC.XferDone)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSpxfer(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.PendingXfers, twainDefs.TwMSG.EndXfer, pxfr);
                if (rc != twainDefs.TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                pics.Add(hbitmap);
            }while (pxfr.Count != 0);

            rc = DSpxfer(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.PendingXfers, twainDefs.TwMSG.Reset, pxfr);
            return(pics);
        }
예제 #4
0
 public void Init(IntPtr hwndp)
 {
     Finish();
     twainDefs.TwRC rc = DSMparent(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Parent, twainDefs.TwMSG.OpenDSM, ref hwndp);
     if (rc == twainDefs.TwRC.Success)
     {
         rc = DSMident(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Identity, twainDefs.TwMSG.GetDefault, srcds);
         if (rc == twainDefs.TwRC.Success)
         {
             hwnd = hwndp;
         }
         else
         {
             rc = DSMparent(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Parent, twainDefs.TwMSG.CloseDSM, ref hwndp);
         }
     }
 }
예제 #5
0
 public void CloseSrc()
 {
     twainDefs.TwRC rc = 0;
     try
     {
         if (srcds.Id != IntPtr.Zero)
         {
             twainDefs.TwUserInterface guif = new twainDefs.TwUserInterface();
             rc = DSuserif(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.UserInterface, twainDefs.TwMSG.DisableDS, guif);
             rc = DSMident(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Identity, twainDefs.TwMSG.CloseDS, srcds);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
예제 #6
0
        public bool Setup()
        {
            twainDefs.TwRC rc = 0;
            CloseSrc();

            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);

                if (appid.Id == IntPtr.Zero)
                {
                    return(false);
                }
            }

            rc = DSMident(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Identity, twainDefs.TwMSG.OpenDS, srcds);

            if (rc != twainDefs.TwRC.Success)
            {
                return(false);
            }

            twainDefs.TwCapability cap = new twainDefs.TwCapability(twainDefs.TwCap.CAP_ENABLEDSUIONLY);
            rc = DScap(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.Capability, twainDefs.TwMSG.Get, cap);

            if (rc != twainDefs.TwRC.Success)
            {
                CloseSrc();
                return(false);
            }

            twainDefs.TwUserInterface guif = new twainDefs.TwUserInterface();
            guif.ShowUI     = 1;
            guif.ModalUI    = 0;
            guif.ParentHand = hwnd;
            rc = DSuserif(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.UserInterface, twainDefs.TwMSG.EnableDSUIOnly, guif);

            if (rc != twainDefs.TwRC.Success)
            {
                CloseSrc();
                return(false);
            }

            return(true);
        }
예제 #7
0
        public TwainCommand PassMessage(ref Message m)
        {
            if (srcds.Id == IntPtr.Zero)
            {
                return(TwainCommand.Not);
            }

            int pos = GetMessagePos();

            winmsg.hwnd    = m.HWnd;
            winmsg.message = m.Msg;
            winmsg.wParam  = m.WParam;
            winmsg.lParam  = m.LParam;
            winmsg.time    = GetMessageTime();
            winmsg.x       = (short)pos;
            winmsg.y       = (short)(pos >> 16);

            Marshal.StructureToPtr(winmsg, evtmsg.EventPtr, false);
            evtmsg.Message = 0;
            twainDefs.TwRC rc = DSevent(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.Event, twainDefs.TwMSG.ProcessEvent, ref evtmsg);

            if (rc == twainDefs.TwRC.NotDSEvent)
            {
                return(TwainCommand.Not);
            }
            if (evtmsg.Message == (short)twainDefs.TwMSG.XFerReady)
            {
                return(TwainCommand.TransferReady);
            }
            if (evtmsg.Message == (short)twainDefs.TwMSG.CloseDSReq)
            {
                return(TwainCommand.CloseRequest);
            }
            if (evtmsg.Message == (short)twainDefs.TwMSG.CloseDSOK)
            {
                return(TwainCommand.CloseOk);
            }
            if (evtmsg.Message == (short)twainDefs.TwMSG.DeviceEvent)
            {
                return(TwainCommand.DeviceEvent);
            }

            return(TwainCommand.Null);
        }
예제 #8
0
        //
        // Function Acquire(int);
        //
        // aNumberOfPages : -1 duplex and multipage scanning support
        //                : 1 or greater scan that many images in.
        //
        public bool Acquire(short aNumberOfPages)
        {
            twainDefs.TwRC rc = 0;
            CloseSrc();
            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);
                if (appid.Id == IntPtr.Zero)
                {
                    return(false);
                }
            }

            rc = DSMident(appid, IntPtr.Zero, twainDefs.TwDG.Control, twainDefs.TwDAT.Identity, twainDefs.TwMSG.OpenDS, srcds);

            if (rc != twainDefs.TwRC.Success)
            {
                return(false);
            }

            rc = SetImageLayout(1, 0, 1, 0, 6, 65, 7, 15);
            twainDefs.TwCapability cap = new twainDefs.TwCapability(twainDefs.TwCap.XferCount, aNumberOfPages);
            rc = DScap(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.Capability, twainDefs.TwMSG.Set, cap);

            if (rc != twainDefs.TwRC.Success)
            {
                CloseSrc();
                return(false);
            }

            twainDefs.TwUserInterface guif = new twainDefs.TwUserInterface();
            guif.ShowUI     = 1;
            guif.ModalUI    = 1;
            guif.ParentHand = hwnd;
            rc = DSuserif(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.UserInterface, twainDefs.TwMSG.EnableDS, guif);

            if (rc != twainDefs.TwRC.Success)
            {
                CloseSrc();
                return(false);
            }

            return(true);
        }
예제 #9
0
        ////////////////////////////////////////////////////////////////////////////
        // Function: SetImageInfo --
        // Author: TWAIN Working Group
        // Input:
        // Output: none
        // Comments:
        //
        public twainDefs.TwRC SetImageLayout(short topWhole, short topFrac, short leftWhole, short leftFrac, short rightWhole, short rightFrac, short bottomWhole, short bottomFrac)
        {
            twainDefs.TwRC          rc            = 0;
            twainDefs.TwImageLayout twImageLayout = new twainDefs.TwImageLayout();

            // Check ImageInfo information
            //rc = CallDSMEntry(appID, dsID, DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET, (TW_MEMREF) twImageLayout);

            rc = DSMImageLayout(appid, srcds, twainDefs.TwDG.Image, twainDefs.TwDAT.ImageLayout, twainDefs.TwMSG.Get, twImageLayout);

            switch (rc)
            {
            case twainDefs.TwRC.Success:
                twImageLayout.Frame.Left.Whole   = leftWhole;
                twImageLayout.Frame.Left.Frac    = (ushort)(leftFrac / 100.0 * 65536);
                twImageLayout.Frame.Top.Whole    = topWhole;
                twImageLayout.Frame.Top.Frac     = (ushort)(topFrac / 100.0 * 65536);
                twImageLayout.Frame.Right.Whole  = rightWhole;
                twImageLayout.Frame.Right.Frac   = (ushort)(rightFrac / 100.0 * 65536);
                twImageLayout.Frame.Bottom.Whole = bottomWhole;
                twImageLayout.Frame.Bottom.Frac  = (ushort)(bottomFrac / 100.0 * 65536);

                //rc = CallDSMEntry(&appID, &dsID, DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET, (TW_MEMREF) & twImageLayout);
                rc = DSMImageLayout(appid, srcds, twainDefs.TwDG.Image, twainDefs.TwDAT.ImageLayout, twainDefs.TwMSG.Set, twImageLayout);
                twainDefs.TwStatus dsmstat1 = new twainDefs.TwStatus();
                rc = DSMstatus(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.Status, twainDefs.TwMSG.Get, dsmstat1);
                break;

            case twainDefs.TwRC.Failure:
                twainDefs.TwStatus dsmstat = new twainDefs.TwStatus();
                rc = DSMstatus(appid, srcds, twainDefs.TwDG.Control, twainDefs.TwDAT.Status, twainDefs.TwMSG.Get, dsmstat);
                break;

            default: break;
            }

            return(rc);
        }