【问题标题】:How to find window's with same class User32.dll winForm如何找到具有相同类 User32.dll winForm 的窗口
【发布时间】:2015-02-07 04:47:15
【问题描述】:

我需要在windows form popup中找到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);

看这张图片:

【问题讨论】:

  • 不,我正在尝试插入用户名和密码并按登录按钮。但是为此我需要找到 txtBox 的 ID。
  • 好的,如果我错了,我很抱歉。我对这种事情比较偏执,我认识的人发生了不好的事情。

标签: c# .net winforms user32 findwindow


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-21
    • 2013-09-23
    • 1970-01-01
    • 2011-08-08
    • 1970-01-01
    • 2012-03-23
    • 2017-09-27
    • 2021-02-27
    相关资源
    最近更新 更多