How to find window's with same class User32.dll winForm

1.4k views Asked by At

I need to find textBox's user name and password and button in windows form popup.

I found the PopUp id ,but me textBox's inside of element/child that have the same classes and i cant find the specific text box that i need , look at image you will understand.

I have there 8 child with same class and each one have same elemets that i need,itried to find them by child after parament but faild.

     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);

See this image:

enter image description here

1

There are 1 answers

0
Vladimir Potapov On BEST ANSWER

I built a function which goes over all children and finds what I need.

I gebuged FindSpecificWindow and use (SendMessage) to set text and like this I found the place of my element by changed text.

Here it is:

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