/// <summary>
        /// Processes window message and indicates wether it is a twain event or not
        /// </summary>
        /// <param name="m">Message send to the application</param>
        /// <returns>The translates TwainMessage if suitable</returns>
        internal Messages ProcessMessage(ref System.Windows.Forms.Message m)
        {
            Messages result = Messages.Null;

            if (dataSource.IsOpen)
            {
                int pos = User32.GetMessagePos();

                windowsMessage.hwnd    = m.HWnd;
                windowsMessage.message = m.Msg;
                windowsMessage.wParam  = m.WParam;
                windowsMessage.lParam  = m.LParam;
                windowsMessage.time    = User32.GetMessageTime();
                windowsMessage.pt_x    = (short)pos;
                windowsMessage.pt_y    = (short)(pos >> 16);

                Marshal.StructureToPtr(windowsMessage, interopStruct.WindowsMessagePointer, false);
                interopStruct.Message = 0;
                ReturnCodes rc = Twain32.ProcessMessage(dataSourceManager.Identity, dataSource.Identity, ref interopStruct);

                if (rc == ReturnCodes.DataSourceEvent)
                {
                    result = (Messages)interopStruct.Message;
                }
            }

            return(result);
        }
示例#2
0
 /// <summary>
 /// Transfers the dib from the
 /// </summary>
 /// <param name="dibPointer"></param>
 /// <returns></returns>
 internal ReturnCodes GetImage(ref IntPtr dibPointer)
 {
     return(Twain32.GetImageNativeXfer(
                dataSourceManager.Identity,
                dataSource.Identity,
                ref dibPointer));
 }
示例#3
0
 /// <summary>
 /// Resets all pending xfers.
 /// </summary>
 /// <returns></returns>
 internal ReturnCodes Reset()
 {
     return(Twain32.ResetPendingXfer(
                dataSourceManager.Identity,
                dataSource.Identity,
                pendingXfersInteropStruct));
 }
 /// <summary>
 /// Receives the default twain datasource
 /// </summary>
 /// <param name="applicationIdentity">Identity of the application</param>
 /// <param name="dataSourceIdentity">Identity of the datasource</param>
 /// <returns>Reply of the twaindriver</returns>
 internal static ReturnCodes GetDefaultDataSource(
     Identity applicationIdentity,
     Identity dataSourceIdentity)
 {
     return(Twain32.DataSourceManagerIdentity(
                applicationIdentity,
                IntPtr.Zero,
                DataGroups.Control,
                DataAttributeTypes.Identity,
                Messages.GetDefault,
                dataSourceIdentity));
 }
 /// <summary>
 /// Closes the datasourcemanager
 /// </summary>
 /// <param name="applicationIdentity">Identity of the application</param>
 /// <param name="parentWindowHandle">Handle of the parentwindow</param>
 /// <returns>Reply of the twaindriver</returns>
 internal static ReturnCodes CloseDataSourceManager(
     Identity applicationIdentity,
     ref IntPtr parentWindowHandle)
 {
     return(Twain32.DataSourceManagerParent(
                applicationIdentity,
                IntPtr.Zero,
                DataGroups.Control,
                DataAttributeTypes.Parent,
                Messages.CloseDataSourceManager,
                ref parentWindowHandle));
 }
        /// <summary>
        /// Closes the datasourcemanager for the current application
        /// </summary>
        /// <returns></returns>
        internal ReturnCodes Close()
        {
            ReturnCodes result = ReturnCodes.Success;

            if (IsOpen)
            {
                result = Twain32.CloseDataSourceManager(this.Identity, ref this.parentWindowHandle);
            }

            this.Identity.Id = IntPtr.Zero;

            return(result);
        }
示例#7
0
        /// <summary>
        /// Shows an userinterface from which one can choose a suitable twain data source
        /// </summary>
        /// <returns>Resonse of the twain driver</returns>
        internal ReturnCodes Select()
        {
            ReturnCodes result = ReturnCodes.Failure;

            Close();

            if (IsClosed)
            {
                result = Twain32.UserSelectDataSource(dataSourceManager.Identity, this.Identity);
            }

            return(result);
        }
示例#8
0
        /// <summary>
        /// Closes the data source that is represeted by an instance of this class
        /// </summary>
        /// <returns>Response of the twain driver</returns>
        internal ReturnCodes Close()
        {
            ReturnCodes result = ReturnCodes.Success;

            if (isOpen)
            {
                result = Twain32.DisableDataSource(dataSourceManager.Identity, this.Identity, new UserInterface());
                result = Twain32.CloseDataSource(dataSourceManager.Identity, this.Identity);
                isOpen = false;
            }

            return(result);
        }
        /// <summary>
        /// Opens the data source manager for the current application
        /// </summary>
        /// <param name="parentWindowHandle"></param>
        /// <returns></returns>
        internal ReturnCodes Open(ref IntPtr parentWindowHandle)
        {
            ReturnCodes result = Twain32.OpenDataSourceManager(this.Identity, ref parentWindowHandle);

            if (
                result == ReturnCodes.Success &&
                this.Identity.Id != IntPtr.Zero
                )
            {
                this.parentWindowHandle = parentWindowHandle;
                this.isOpen             = true;
            }

            return(result);
        }
示例#10
0
        /// <summary>
        /// Starts the scanning process
        /// </summary>
        /// <param name="parentWindowHandle">Parent window of the twain driver's userinterface</param>
        /// <returns>Resonse of the twain driver</returns>
        internal ReturnCodes Enable(IntPtr parentWindowHandle)
        {
            ReturnCodes result = ReturnCodes.Failure;

            if (IsOpen)
            {
                UserInterface guif = new UserInterface();
                guif.ShowUserInterface  = 1;
                guif.ModalUserInterface = 1;
                guif.ParentHandle       = parentWindowHandle;

                result = Twain32.EnableDataSource(dataSourceManager.Identity, this.Identity, guif);
            }

            return(result);
        }
示例#11
0
        /// <summary>
        /// Opens the data source represented by an object of this class
        /// </summary>
        /// <returns>Response of the twain driver</returns>
        internal ReturnCodes Open()
        {
            Close();

            ReturnCodes openResult = Twain32.OpenDataSource(dataSourceManager.Identity, this.Identity);

            Capability  capability      = new Capability(dataSourceManager, this, Capabilities.XferCount, -1);
            ReturnCodes xferCountResult = capability.Set();

            ReturnCodes result = ReturnCodes.Failure;

            if (
                openResult == ReturnCodes.Success &&
                xferCountResult == ReturnCodes.Success &&
                this.Identity.Id != IntPtr.Zero
                )
            {
                result = ReturnCodes.Success;
                isOpen = true;
            }

            return(result);
        }
 /// <summary>
 /// Received the data of a pending xfer
 /// </summary>
 /// <returns></returns>
 internal ReturnCodes Get()
 {
     return(Twain32.GetImageInfo(dataSourceManager.Identity, dataSource.Identity, ref this.interopStruct));
 }
示例#13
0
 /// <summary>
 /// Receives the default twain data source
 /// </summary>
 /// <returns></returns>
 internal ReturnCodes GetDefault()
 {
     return(Twain32.GetDefaultDataSource(dataSourceManager.Identity, this.Identity));
 }
 /// <summary>
 /// Sets the capability represented by the object to the associated data source
 /// </summary>
 /// <returns></returns>
 internal ReturnCodes Set()
 {
     return(Twain32.SetCapability(this.dataSourceManager.Identity, this.dataSource.Identity, this));
 }