-1

我需要在 windows 窗体弹出窗口中找到 textBox 的用户名和密码以及按钮。

我找到了 PopUp id,但我的 textBox 在具有相同类的元素/子项内部,我找不到我需要的特定文本框,看看你会明白的图像。

我有 8 个同班的孩子,每个孩子都有我需要的相同元素,在参数之后试图通过孩子找到它们但失败了。

     int LoginPop = FindWindow(sLoginPopUpClassName, sLoginPopUpName);//found
      int LoginPopForm = FindWindowEx(LoginPop, 0, sLoginPopUpClassName, sLoginPopUpName);//found
  int LoginPopUserNameArea = FindWindowEx(LoginPopForm, 0, ClassName, sLoginPopUpAreaName);    

    > LoginPopForm have 8 child with my txtbox's

    //here i tried to find my txtBox's and button with child after ,but fail.
   int LoginPopUserNameArea = FindWindowEx(LoginPopForm, 7, sClassName, saName);//CtrlNotifySink 
   int LoginPopPasswordArea = FindWindowEx(LoginPopForm, 8, sClassName, sName);
   int LoginPopButtonArea = FindWindowEx(LoginPopForm, 3, sClassName, sName);


   int LoginPopTextBoxUserName = FindWindowEx(LoginPopUserNameArea, 0, sClassName, sName);
   int LoginPopTextBoxPassword = FindWindowEx(LoginPopPasswordArea, 0, sClassName, sName);
   int LoginPopButtonOk = FindWindowEx(LoginPopButtonArea, 0, ClassName, Name);

看这张图片:

在此处输入图像描述

4

1 回答 1

0

我构建了一个函数,它遍历所有孩子并找到我需要的东西。

我对 FindSpecificWindow 进行了调试并使用 (SendMessage) 设置文本,就像这样,我通过更改的文本找到了我的元素的位置。

这里是:

ChildPlace = 30;//global parameter,after gebug i found that txt Paswword  is 30 child
     foundWindow = 0;
     int txtPassword = FindSpecificWindow(LoginPopForm);
     SendMessage(txtPassword, WM_SETTEXT, 0, strPassword); 

public static int FindSpecificWindow(int intWhdrNew)
        {
            int prevChild2 = 0;
            int currChild2 = 0;

            if (intWhdrNew != 0)
            {
                try
                {

                    do
                    {

                        currChild2 = FindWindowEx(intWhdrNew, prevChild2, null, null);

                     // SendMessage(currChild2, WM_SETTEXT, 0, del.ToString());
                        //del++;
                        ChildPlace--;
                        if (currChild2 != 0)
                        {
                            if (ChildPlace == 0)
                            {
                                foundWindow = currChild2;
                                break;

                            }
                            FindSpecificWindow(currChild2) ;
                            prevChild2 = currChild2;

                        }
                    }
                    while (currChild2 != 0 && ChildPlace!=0);
                }
                catch (Exception ex)
                {

                }
            }
            else
            {

            }
            return foundWindow;
        }
于 2014-12-10T14:53:27.987 回答