如何找到具有相同类User32.dll winForm的窗口

时间:2014-12-09 10:17:58

标签: c# .net winforms user32 findwindow

我需要在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);

看到这张图片:

enter image description here

1 个答案:

答案 0 :(得分:0)

我建立了一个能够覆盖所有孩子并找到我需要的功能。

我gebuged 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;
        }