Beispiel #1
0
 public MyFormat(int dummy)
 {
     _transferMode       = WiaTransferMode.None;
     _transferModeString = string.Empty;
     _formatName         = string.Empty;
     _formatCLSID        = string.Empty;
     _guidFormat         = Guid.Empty;
 }
Beispiel #2
0
        private void InitializeWia()
        {
            if (_mySettings._settings.wiaVersion == 0)
            {
                return;
            }

            _wiaVersion   = (WiaVersion)_mySettings._settings.wiaVersion;
            _wiaAvailable = WiaSession.IsAvailable(_wiaVersion);

            if (_wiaAvailable)
            {
                _wiaSession = new WiaSession();
                _wiaSession.Startup(_wiaVersion);
                _miWiaSelectSource.Enabled = true;

                // Set the default acquire path for file transfer to My Documents folder.
                string myDocumentsPath;
                HelperFunctions.GetFormatFilterAndExtension();

                myDocumentsPath             = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                _wiaAcquireOptions.FileName = string.Format("{0}{1}{2}", myDocumentsPath, "\\WiaTest.", HelperFunctions.Extension);

                if (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) // GetProperties() method not called yet.
                {
                    _wiatransferMode = WiaTransferMode.Memory;
                }
                else
                {
                    _wiatransferMode = _wiaProperties.DataTransfer.TransferMode;
                }

                _wiaSession.AcquireEvent += new EventHandler <WiaAcquireEventArgs>(_wiaSession_AcquireEvent);
            }
            else
            {
                _miWiaSelectSource.Enabled = false;
            }

            _wiaerrorList        = new ArrayList();
            _enumeratedItemsList = new ArrayList();
            _capabilitiesList    = new ArrayList();
            _formatsList         = new ArrayList();
            _flagValuesStrings   = new ArrayList();

            _wiaSourceSelected = _mySettings._settings.wiaSelectedDevice != null;
            if (_wiaSourceSelected)
            {
                try
                {
                    _wiaSession.SelectDevice(_mySettings._settings.wiaSelectedDevice);
                }
                catch
                {
                    _wiaSourceSelected = false;
                }
            }
        }
Beispiel #3
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // initialize the codecs object
            _codecs = new RasterCodecs();

            _wiaAvailable = WiaSession.IsAvailable(_wiaVersion);
            if (_wiaAvailable)
            {
                _wiaSession = new WiaSession();
                _wiaSession.Startup(_wiaVersion);
                _miWiaSelectSource.Enabled = true;

                // Set the default acquire path for file transfer to My Documents folder.
                string myDocumentsPath;
                HelperFunctions.GetFormatFilterAndExtension();

                myDocumentsPath             = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                _wiaAcquireOptions.FileName = string.Format("{0}{1}{2}", myDocumentsPath, "\\" + DemosGlobalization.GetResxString(GetType(), "Resx_WiaTest") + ".", HelperFunctions.Extension);

                if (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) // GetProperties() method not called yet.
                {
                    _transferMode = WiaTransferMode.Memory;
                }
                else
                {
                    _transferMode = _wiaProperties.DataTransfer.TransferMode;
                }

                _wiaSession.AcquireEvent += new EventHandler <WiaAcquireEventArgs>(_wiaSession_AcquireEvent);
            }
            else
            {
                _miWiaSelectSource.Enabled = false;
            }

            EnableMenuItems(false);
            _errorList         = new ArrayList();
            _capabilitiesList  = new ArrayList();
            _formatsList       = new ArrayList();
            _flagValuesStrings = new ArrayList();
        }
Beispiel #4
0
        private void _miWiaAcquire_Click(object sender, System.EventArgs e)
        {
            WiaAcquireFlags flags        = WiaAcquireFlags.None;
            bool            showProgress = true;

            _progressDlg = new ProgressForm(DemosGlobalization.GetResxString(GetType(), "Resx_Transferring"), "", 100);

            _wiaAcquiring = true;

            if (_showUserInterface)
            {
                flags = WiaAcquireFlags.UseCommonUI | WiaAcquireFlags.ShowUserInterface;
            }
            else
            {
                // Check if the selected device is scanner and that it has multiple sources (Feeder & Flatbed)
                // then show the select source dialog box.
                if (SelectAcquireSource() != DialogResult.OK)
                {
                    _wiaAcquiring = false;
                    return;
                }
            }

            if (_showUserInterface)
            {
                if (_wiaVersion == WiaVersion.Version2)
                {
                    showProgress = false;
                }
            }

            if (showProgress)
            {
                // Show the progress dialog.
                _progressDlg.Show(this);
            }

            try
            {
                _wiaSession.AcquireOptions = _wiaAcquireOptions;

                if (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) // GetProperties() method not called yet.
                {
                    _transferMode = WiaTransferMode.Memory;
                }
                else
                {
                    _transferMode = _wiaProperties.DataTransfer.TransferMode;
                }

                // Disable the minimize and maximize buttons.
                this.MinimizeBox = false;
                this.MaximizeBox = false;

#if !LEADTOOLS_V19_OR_LATER
                DialogResult dialogResult = _wiaSession.Acquire(this, _sourceItem, flags);
#else
                DialogResult dialogResult = _wiaSession.Acquire(this.Handle, _sourceItem, flags);
#endif // #if !LEADTOOLS_V19_OR_LATER
                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                // Enable back the minimize and maximize buttons.
                this.MinimizeBox = true;
                this.MaximizeBox = true;

                if (_progressDlg.Visible)
                {
                    if (!_progressDlg.Abort)
                    {
                        _progressDlg.Dispose();
                    }
                }

                if (_sourceItem != null)
                {
                    _sourceItem = null;
                }

                if (_wiaSession.FilesCount > 0) // This property indicates how many files where saved when the transfer mode is File mode.
                {
                    string strMsg = DemosGlobalization.GetResxString(GetType(), "Resx_PagesSavedTo") + "\n\n";
                    if (_wiaSession.FilesPaths.Count > 0)
                    {
                        for (int i = 0; i < _wiaSession.FilesPaths.Count; i++)
                        {
                            string strTemp = string.Format("{0}\n", _wiaSession.FilesPaths[i]);
                            strMsg += strTemp;
                        }
                        MessageBox.Show(this, strMsg, DemosGlobalization.GetResxString(GetType(), "Resx_FileTransfer"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    // WIA 2.0 sometimes doesn't return the acquired files count and paths, so this message will show
                    // the directory where the saved files were saved.
                    if (_wiaVersion == WiaVersion.Version2)
                    {
                        int    len = _wiaAcquireOptions.FileName.LastIndexOf('\\');
                        string strFilesDirectory = _wiaAcquireOptions.FileName.Substring(0, len);
                        string strMsg            = string.Format(DemosGlobalization.GetResxString(GetType(), "Resx_PagesSavedTo") + "\n\n{0}", strFilesDirectory);
                        MessageBox.Show(this, strMsg, DemosGlobalization.GetResxString(GetType(), "Resx_FileTransfer"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                _wiaAcquiring = false;
            }
            catch (Exception ex)
            {
                // Enable back the minimize and maximize buttons.
                this.MinimizeBox = true;
                this.MaximizeBox = true;

                _wiaAcquiring = false;
                if (_progressDlg.Visible)
                {
                    if (!_progressDlg.Abort)
                    {
                        _progressDlg.Dispose();
                    }
                }

                Messager.ShowError(this, ex);
            }
            finally
            {
                // Enable back the minimize and maximize buttons.
                this.MinimizeBox = true;
                this.MaximizeBox = true;

                _wiaAcquiring = false;
            }
        }
Beispiel #5
0
        private void _miWiaAcquire_Click(object sender, System.EventArgs e)
        {
            bool bTopMost = logWindow.TopMost;

            logWindow.TopMost = false;
            WiaAcquireFlags flags;
            bool            showProgress = true;

            _progressDlg = new ProgressForm("Transferring...", "", 100);

            _wiaAcquiring = true;

            flags = WiaAcquireFlags.UseCommonUI;
            if (_showUserInterface)
            {
                flags |= WiaAcquireFlags.ShowUserInterface;
            }
            else
            {
                // Check if the selected device is scanner and that it has multiple sources (Feeder & Flatbed)
                // then show the select source dialog box.
                if (SelectAcquireSource() != DialogResult.OK)
                {
                    _wiaAcquiring     = false;
                    logWindow.TopMost = bTopMost;
                    return;
                }
            }

            if (_showUserInterface)
            {
                if (_wiaVersion == WiaVersion.Version1)
                {
                    showProgress = true;
                }
                else
                {
                    showProgress = false;
                }
            }
            else
            {
                showProgress = true;
            }

            if (showProgress)
            {
                // Show the progress dialog.
                _progressDlg.Show(this);
            }

            try
            {
                _wiaSession.AcquireOptions = _wiaAcquireOptions;

                if (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) // GetProperties() method not called yet.
                {
                    _wiatransferMode = WiaTransferMode.Memory;
                }
                else
                {
                    _wiatransferMode = _wiaProperties.DataTransfer.TransferMode;
                }

                // Disable the minimize and maximize buttons.
                this.MinimizeBox = false;
                this.MaximizeBox = false;

                wiaImageCollection = new ListImageBox.ImageCollection("WIA Scanned");

#if LEADTOOLS_V19_OR_LATER
                _wiaSession.Acquire(this.Handle, _sourceItem, flags);
#else
                _wiaSession.Acquire(this, _sourceItem, flags);
#endif // #if LEADTOOLS_V19_OR_LATER

                // Enable back the minimize and maximize buttons.
                this.MinimizeBox = true;
                this.MaximizeBox = true;

                if (_progressDlg.Visible)
                {
                    if (!_progressDlg.Abort)
                    {
                        _progressDlg.Dispose();
                    }
                }

                if (_enumeratedItemsList.Count > 0)
                {
                    _enumeratedItemsList.Clear();
                }
                if (_sourceItem != null)
                {
                    _sourceItem = null;
                }

                if (_wiaSession.FilesCount > 0) // This property indicates how many files where saved when the transfer mode is File mode.
                {
                    string strMsg = "Acquired page(s) were saved to:\n\n";
                    if (_wiaSession.FilesPaths.Count > 0)
                    {
                        for (int i = 0; i < _wiaSession.FilesPaths.Count; i++)
                        {
                            string strTemp = string.Format("{0}\n", _wiaSession.FilesPaths[i]);
                            strMsg += strTemp;
                        }
                        MessageBox.Show(this, strMsg, "File Transfer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                _wiaAcquiring = false;
            }
            catch (Exception ex)
            {
                // Enable back the minimize and maximize buttons.
                this.MinimizeBox = true;
                this.MaximizeBox = true;

                _wiaAcquiring = false;
                if (_progressDlg.Visible)
                {
                    if (!_progressDlg.Abort)
                    {
                        _progressDlg.Dispose();
                    }
                }

                Messager.ShowError(this, ex);
            }
            if (wiaImageCollection.Images.Count > 0)
            {
                _lstBoxPages.AddImageCollection(wiaImageCollection);
            }
            logWindow.TopMost = bTopMost;
        }