Example #1
0
        /// <summary>
        /// Create and destroy our toolkit object, as needed...
        /// </summary>
        /// <param name="a_szDg">Data group</param>
        /// <param name="a_szDat">Data argument type</param>
        /// <param name="a_szMsg">Operation</param>
        private void ManageToolkit(string a_szDg, string a_szDat, string a_szMsg)
        {
            // Handle MSG_OPENDSM...
            if (a_szMsg == "MSG_OPENDSM")
            {
                // Init stuff...
                m_blClosing = false;

                // Validate...
                if (m_twaincstoolkit != null)
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(already open)");
                    return;
                }

                // Create our image capture object...
                try
                {
                    m_twaincstoolkit = new TWAINCSToolkit
                                       (
                        this.Handle,
                        WriteOutput,
                        ReportImage,
                        SetMessageFilter,
                        "TWAIN Working Group",
                        "TWAIN Sharp",
                        "TWAIN Sharp Test App",
                        2,
                        3,
                        new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                        "USA",
                        "testing...",
                        "ENGLISH_USA",
                        1,
                        0,
                        m_checkboxUseTwain32.Checked,
                        m_checkboxUseCallbacks.Checked
                                       );
                }
                catch
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(unable to start)");
                    m_twaincstoolkit = null;
                    return;
                }
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.SUCCESS.ToString());

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = false;
                    m_checkboxUseCallbacks.Enabled = false;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle MSG_CLOSEDSM...
            else if (a_szMsg == "MSG_CLOSEDSM")
            {
                // Issue the command...
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.SUCCESS.ToString());
                m_blClosing = true;
                m_twaincstoolkit.Cleanup();
                m_twaincstoolkit = null;

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                    m_checkboxUseCallbacks.Enabled = true;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle anything else...
            else
            {
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.BADPROTOCOL.ToString());
            }
        }
Example #2
0
        /// <summary>
        /// Create and destroy our toolkit object, as needed...
        /// </summary>
        /// <param name="a_szDg">Data group</param>
        /// <param name="a_szDat">Data argument type</param>
        /// <param name="a_szMsg">Operation</param>
        private void ManageToolkit(string a_szDg, string a_szDat, string a_szMsg)
        {
            // Handle MSG_OPENDSM...
            if (a_szMsg == "MSG_OPENDSM")
            {
                // Init stuff...
                m_blClosing = false;

                // Validate...
                if (m_twaincstoolkit != null)
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(already open)");
                    return;
                }

                // Create our image capture object...
                try
                {
                    string[] aszTwidentity = m_richtextboxCapability.Text.Split(',');
                    if ((aszTwidentity == null) || (aszTwidentity.Length < 9))
                    {
                        m_twaincstoolkit = new TWAINCSToolkit
                                           (
                            this.Handle,
                            WriteOutput,
                            ReportImage,
                            SetMessageFilter,
                            "TWAIN Working Group",
                            "TWAIN Sharp",
                            "TWAIN Sharp Test App",
                            2,
                            4,
                            new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                            "USA",
                            "testing...",
                            "ENGLISH_USA",
                            1,
                            0,
                            m_checkboxUseTwain32.Checked,
                            m_checkboxUseCallbacks.Checked,
                            RunInUiThread,
                            this
                                           );
                    }
                    else
                    {
                        m_twaincstoolkit = new TWAINCSToolkit
                                           (
                            this.Handle,
                            WriteOutput,
                            ReportImage,
                            SetMessageFilter,
                            aszTwidentity[0],
                            aszTwidentity[1],
                            aszTwidentity[2],
                            ushort.Parse(aszTwidentity[3]),
                            ushort.Parse(aszTwidentity[4]),
                            new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                            aszTwidentity[6],
                            aszTwidentity[7],
                            aszTwidentity[8],
                            1,
                            0,
                            m_checkboxUseTwain32.Checked,
                            m_checkboxUseCallbacks.Checked,
                            RunInUiThread,
                            this
                                           );
                    }
                }
                catch (Exception exception)
                {
                    TWAINWorkingGroup.Log.Error("exception - " + exception.Message);
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(unable to start)");
                    m_twaincstoolkit = null;
                    return;
                }
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.SUCCESS.ToString());

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = false;
                    m_checkboxUseCallbacks.Enabled = false;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle MSG_CLOSEDSM...
            else if (a_szMsg == "MSG_CLOSEDSM")
            {
                // Issue the command...
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.SUCCESS.ToString());
                m_blClosing = true;
                m_twaincstoolkit.Cleanup();
                m_twaincstoolkit = null;

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                    m_checkboxUseCallbacks.Enabled = true;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle anything else...
            else
            {
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.BADPROTOCOL.ToString());
            }
        }
Example #3
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Functions...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Functions...

        /// <summary>
        /// Init our form, and our TWAIN class.  You might want to consider
        /// moving TWAIN into its own thread, or even running it from a
        /// separate process, so that the main application is always responsive
        /// no matter what's going on in the driver...
        /// </summary>
        public FormMain()
        {
            ContextMenu contextmenu;
            MenuItem    menuitem;

            // Init our form...
            InitializeComponent();

            // Make sure we cleanup if unexpectedly closed...
            this.FormClosing += new FormClosingEventHandler(FormMain_FormClosing);

            // This next bit establishes the rules for the various DSM's on the
            // various operating systems.

            // Windows controls...
            if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
            {
                m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                m_checkboxUseCallbacks.Enabled = true;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Linux controls...
            else if (TWAINCSToolkit.GetPlatform() == "LINUX")
            {
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
            }

            // Mac OS X controls...
            else if (TWAINCSToolkit.GetPlatform() == "MACOSX")
            {
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
            }

            // Autoscroll the text in our output box...
            m_richtextboxOutput.HideSelection      = false;
            m_richtextboxOutput.SelectionProtected = false;

            // Init other stuff...
            m_twaincstoolkit = null;

            // Init our image controls...
            InitImage();

            // Load our triplet dropdown...
            this.m_comboboxDG.Items.AddRange(TWAINCSToolkit.GetTwainDg());
            this.m_comboboxDAT.Items.AddRange(TWAINCSToolkit.GetTwainDat());
            this.m_comboboxMSG.Items.AddRange(TWAINCSToolkit.GetTwainMsg());

            // Init our triplet dropdown...
            AutoDropdown("", "", "");

            // Context menu for our value box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxcapability_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxcapability_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxCapability.ContextMenu = contextmenu;
            contextmenu = null;

            // Context menu for our output box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxoutput_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxoutput_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxOutput.ContextMenu = contextmenu;
            contextmenu = null;
        }
Example #4
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Functions...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Functions...

        /// <summary>
        /// Init our form, and our TWAIN class.  You might want to consider
        /// moving TWAIN into its own thread, or even running it from a
        /// separate process, so that the main application is always responsive
        /// no matter what's going on in the driver...
        /// </summary>
        public FormMain()
        {
            ContextMenu contextmenu;
            MenuItem    menuitem;

            // Init our form...
            InitializeComponent();

            // Open the log in our working folder, and say hi...
            TWAINWorkingGroup.Log.Open("TWAINCSTst", ".", 1);
            TWAINWorkingGroup.Log.Info("TWAINCSTst v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString());

            // Make sure we cleanup if unexpectedly closed...
            this.FormClosing += new FormClosingEventHandler(FormMain_FormClosing);

            // This next bit establishes the rules for the various DSM's on the
            // various operating systems.

            // Windows controls...
            if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
            {
                // Choose between TWAIN_32 and TWAINDSM, note that we always default
                // to the open source TWAIN DSM...
                m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                m_checkboxUseCallbacks.Enabled = true;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Linux controls...
            else if (TWAINCSToolkit.GetPlatform() == "LINUX")
            {
                // We don't give the user control between the DSM versions, because
                // the 64-bit problem is handled as seamlessly as possible...
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Mac OS X controls...
            else if (TWAINCSToolkit.GetPlatform() == "MACOSX")
            {
                // Choose between /System/Library/Frameworks/TWAIN.framework and
                // /Library/Frameworks/TWAINDSM.framework, note that we always default
                // to the open source TWAIN DSM...
                m_checkboxUseTwain32.Enabled   = true;
                m_checkboxUseCallbacks.Enabled = false;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Autoscroll the text in our output box...
            m_richtextboxOutput.HideSelection      = false;
            m_richtextboxOutput.SelectionProtected = false;

            // Init other stuff...
            m_twaincstoolkit = null;

            // Init our image controls...
            InitImage();

            // Load our triplet dropdown...
            this.m_comboboxDG.Items.AddRange(TWAINCSToolkit.GetTwainDg());
            this.m_comboboxDAT.Items.AddRange(TWAINCSToolkit.GetTwainDat());
            this.m_comboboxMSG.Items.AddRange(TWAINCSToolkit.GetTwainMsg());

            // Init our triplet dropdown...
            AutoDropdown("", "", "");

            // Context menu for our value box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxcapability_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxcapability_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxCapability.ContextMenu = contextmenu;
            contextmenu = null;

            // Context menu for our output box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxoutput_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxoutput_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxOutput.ContextMenu = contextmenu;
            contextmenu = null;

            // Set the capbility box to our app info...
            m_richtextboxCapability.Text =
                "TWAIN Working Group," +
                "TWAIN Sharp," +
                "TWAIN Sharp Test App," +
                "2," +
                "4," +
                "0x20000003," +
                "USA," +
                "testing...," +
                "ENGLISH_USA";
        }