示例#1
0
        private void SearchText(bool bClickText)
        {
            // get the hwnd
            int hwnd;

            hwnd = int.Parse(txtHandle.Text, System.Globalization.NumberStyles.HexNumber);

            // get the rectangle
            int x = int.Parse(txtX.Text);
            int y = int.Parse(txtY.Text);
            int w = int.Parse(txtWidth.Text);
            int h = int.Parse(txtHeight.Text);

            int occurence = int.Parse(txtOccurence.Text);

            try
            {
                // create the rectangle of the of the
                // clicked region
                rect rectangle = ComFactory.Instance.NewRect();
                rectangle.RLeft   = x;
                rectangle.RRight  = x + w;
                rectangle.RTop    = y;
                rectangle.RBottom = y + h;

                m_tCapture.UseClientCoordinates = true;

                // get the rectangle of the searched text
                rect foundRect = null;
                if (radioNative.Checked == true)
                {
                    foundRect = m_tCapture.GetRectFromText(hwnd, txtSearch.Text, rectangle, occurence);
                }
                else if (radioOCR.Checked == true)
                {
                    string strLang = (string)comboLang.Items[comboLang.SelectedIndex];
                    foundRect = m_tOCRCapture.GetRectFromText(hwnd, txtSearch.Text, rectangle, strLang, false, occurence);
                }

                // show the coordinates
                txtFoundX.Text = foundRect.RLeft.ToString();
                txtFoundY.Text = foundRect.RTop.ToString();
                txtFoundW.Text = foundRect.width().ToString();
                txtFoundH.Text = foundRect.height().ToString();

                if (bClickText)
                {
                    UIElem uiElem = ComFactory.Instance.NewUIElem();
                    uiElem.InitializeFromID(txtID.Text, false);

                    uiElem.Click(foundRect.RLeft + 2, foundRect.RTop + 2, GetClickFlags());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }