Beispiel #1
0
            public WindowsTree FiltedbyClassName(string classname)
            {
                WindowsTree wt    = new WindowsTree();
                int         isort = 0;

                for (int i = 0; i < this.WindowCount; i++)
                {
                    if (this.winfos[i].classname == classname)
                    {
                        wt.winfos[isort].hwnd      = this.winfos[i].hwnd;
                        wt.winfos[isort].title     = this.winfos[i].title;
                        wt.winfos[isort].classname = this.winfos[i].classname;
                        isort++;
                    }
                }
                wt.WindowCount = isort;
                if (wt.WindowCount > 0)
                {
                    return(wt);
                }
                else
                {
                    return(null);
                }
            }
Beispiel #2
0
        //根据类名获取句柄
        public IntPtr GetWindowHandlebyClass(String Class)
        {
            bool      flg_success = false;
            string    tmp;
            AccessWin aw = new AccessWin();

            aw.windowsTree = aw.ListWindow((IntPtr)0);
            int i;

            for (i = 0; i < aw.windowsTree.WindowCount; i++)
            {
                tmp = "";
                if (aw.windowsTree.winfos[i].classname.Length >= Class.Length)
                {
                    tmp = aw.windowsTree.winfos[i].classname.Substring(0, Class.Length); //prevent string too short to be cut
                    if (Class == tmp)
                    {
                        break;
                    }
                }
            }
            if (i >= aw.windowsTree.WindowCount)   //can't find Top window
            {
                flg_success = false;
                if (flg_success == false)
                {
                    return(new IntPtr(-1));
                }
            }
            int    currWindowNO = i;
            IntPtr currWnd      = aw.windowsTree.winfos[currWindowNO].hwnd;

            return(currWnd);
        }
Beispiel #3
0
            public WindowsTree FiltedbyHWND(int HWND)
            {
                WindowsTree wt    = new WindowsTree();
                int         isort = 0;

                for (int i = 0; i < this.WindowCount; i++)
                {
                    if (this.winfos[i].hwnd.ToInt32() == HWND)
                    {
                        wt.winfos[isort].hwnd      = this.winfos[i].hwnd;
                        wt.winfos[isort].title     = this.winfos[i].title;
                        wt.winfos[isort].classname = this.winfos[i].classname;
                        isort++;
                    }
                }
                wt.WindowCount = isort;
                if (wt.WindowCount > 0)
                {
                    return(wt);
                }
                else
                {
                    return(null);
                }
            }
Beispiel #4
0
 //根据句柄获取子控件序列,含子窗口
 public WindowsTree ListWindow(IntPtr hwnd)
 {
     tmp             = new WindowsTree();
     tmp.WindowCount = 0;
     NativeMethods.EnumChildWindows(hwnd, new WNDENUMPROC(GerProcessInfo_back), 0);
     this.windowsTree = tmp;
     return(tmp);
 }
Beispiel #5
0
        public bool CloseMessageBox(ref string message, IntPtr handle)
        {
            try {
                WindowsTree wt = ListWindow(handle);
                for (int i = 0; i < wt.WindowCount; i++)
                {
                    WindowInfo info = wt.winfos[i];
                    //记录提示信息
                    if (info.title == "提示")
                    {
                        if ((sw.ElapsedMilliseconds > 20000) || (ptr_LastClosedHWND != info.hwnd)) //据上次关闭大于3S,或者要关闭的窗体是新窗体 (3S钟内不重复关闭一个窗体)
                        {
                            sw.Reset();
                            sw.Restart();
                            ptr_LastClosedHWND = info.hwnd;
                            AccessWin   aw       = new AccessWin();
                            WindowsTree wtsub    = aw.ListWindow(info.hwnd);
                            WindowsTree wtfilter = wtsub.FiltedbyClassName("Static");
                            for (int j = 0; j < wtfilter.WindowCount; j++)
                            {
                                WindowInfo infosub = wtfilter.winfos[j];
                                message = message + infosub.title + " ";
                                message = message.Trim();
                            }

                            //关闭窗口
                            WindowsTree wtfilter2 = wtsub.FiltedbyClassName("Button");
                            ClickButton(wtfilter2.winfos[0].hwnd);
                            ClickButton(wtfilter2.winfos[0].hwnd);
                            return(true);
                        }
                        else
                        {
                            int iii = 0;
                            iii++;
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                Console.Write(ee.StackTrace);
                return(false);
            }
            return(false);
        }
Beispiel #6
0
        public string FindText(IntPtr handle) //查找所有子控件包含的文本
        {
            //string message = "";
            //try
            //{
            //    WindowsTree wt = ListWindow(handle);
            //    for (int i = 0; i < wt.WindowCount; i++)
            //    {
            //        //记录提示信息
            //        WindowsTree wtfilter = wt.FiltedbyClassName("Static");
            //        for (int j = 0; j < wtfilter.WindowCount; j++)
            //        {
            //            WindowInfo infosub = wtfilter.winfos[j];
            //            message = message + infosub.title + " ";
            //            message = message.Trim();
            //        }
            //    }
            //}
            StringBuilder message   = new StringBuilder("");
            string        s_message = "";

            try
            {
                WindowsTree wt = ListWindow(handle);
                //记录提示信息
                WindowsTree wtfilter = wt.FiltedbyClassName("Static");
                if (wtfilter == null)
                {
                    return("");
                }
                for (int j = 0; j < wtfilter.WindowCount; j++)
                {
                    WindowInfo infosub = wtfilter.winfos[j];
                    message.Append(infosub.title + " ");
                    s_message = message.ToString().Trim();;
                }
            }
            catch (Exception ee)
            {
                Console.Write(ee.StackTrace);
                return("");
            }
            return(s_message);
        }
Beispiel #7
0
        public bool CloseSystemTreeBox(string title, ref string message, IntPtr handle)
        {
            try
            {
                WindowsTree wt = ListWindow(handle);
                for (int i = 0; i < wt.WindowCount; i++)
                {
                    WindowInfo info = wt.winfos[i];
                    //记录提示信息
                    if (info.title == title)
                    {
                        AccessWin   aw       = new AccessWin();
                        WindowsTree wtsub    = aw.ListWindow(info.hwnd);
                        WindowsTree wtfilter = wtsub.FiltedbyClassName("SysListView32");

                        DataTable dt = aw.GetListViewContent(wtfilter.winfos[0].hwnd);
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            for (int k = 0; k < dt.Columns.Count; k++)
                            {
                                message = message + dt.Rows[j][k].ToString() + "/";
                            }
                        }

                        //关闭窗口
                        WindowsTree wtfilter2 = wtsub.FiltedbyClassName("Button");
                        ClickButton(wtfilter2.winfos[0].hwnd);
                        ClickButton(wtfilter2.winfos[0].hwnd);
                        return(true);
                    }
                }
            }
            catch (Exception ee)
            {
                Console.Write(ee.StackTrace);
                return(false);
            }
            return(false);
        }
Beispiel #8
0
 public DataTable toDatatable(WindowsTree wt)
 {
     if (wt != null)
     {
         DataTable dt = new DataTable();
         dt.Columns.Clear();
         dt.Rows.Clear();
         dt.Columns.Add("序号");
         dt.Columns.Add("句柄");
         dt.Columns.Add("标题");
         dt.Columns.Add("类名");
         for (int i = 0; i < wt.WindowCount; i++)
         {
             dt.Rows.Add(new string[] { (i + 1).ToString("D3"), wt.winfos[i].hwnd.ToString("X"), wt.winfos[i].title, wt.winfos[i].classname });
         }
         return(dt);
     }
     else
     {
         return(null);
     }
 }