コード例 #1
0
ファイル: Form1.cs プロジェクト: TylerHaigh/SDK
        private void PerformWndCapture(UIElem uiElem)
        {
            if (m_bRegOrWnd == true)
            {
                // if a region was selected
                MessageBox.Show("You selected a region!");
                return;
            }

            if (uiElem == null)
            {
                return;
            }

            // get the text and font
            //stdole.IFontDisp font;
            string strText = "";
            CaptureMethod captMethod = GetCaptureMethod();
            if (captMethod == CaptureMethod.NATIVE)
            {
                try
                {
                    // preserve layout checkbox
                    if (checkLayout.Checked == true)
                    {
                        m_tCapture.FormattedText = true;
                    }
                    strText = m_tCapture.GetTextFromUIElem(uiElem);
                    //txtFont.Text = font.Name;
                    //txtFontSize.Text = font.Size.ToString();
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (captMethod == CaptureMethod.FULL_TEXT)
            {
                try
                {
                    strText = m_tFullTextCapt.GetFullTextFromUIElem(uiElem);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (captMethod == CaptureMethod.OCR)
            {
                try
                {
                    string strLang = (string)comboLang.Items[comboLang.SelectedIndex];
                    
                    strText = m_tOCRCapture.GetTextFromUIElem(uiElem, strLang, false);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            txtResult.Text = strText;
        }