Esempio n. 1
0
        public static List <WindowInfo> GetAllDesktopWindows(IntPtr pHWnd)
        {
            List <WindowInfo> wndParam = new List <WindowInfo>();


            List <int> child = WindowFormAPI.GetChildWindows(pHWnd.ToInt32());

            foreach (var item in child)
            {
                IntPtr        hWnd = new IntPtr(item);
                WindowInfo    wnd  = new WindowInfo();
                StringBuilder sb   = new StringBuilder(256);
                wnd.hWnd = hWnd;
                //标题
                GetWindowTextW(hWnd, sb, sb.Capacity);
                wnd.szWindowName = sb.ToString();


                //类名
                GetClassNameW(hWnd, sb, sb.Capacity);
                wnd.szClassName = sb.ToString();

                //进程ID
                GetWindowThreadProcessId(hWnd.ToInt32(), out wnd.ProcessId);
                //控件id
                wnd.ItemId = WindowFormAPI.GetDlgCtrlID(hWnd);
                //父句柄
                wnd.FatherhWnd = WindowFormAPI.GetParent(hWnd);
                wndParam.Add(wnd);
                wndParam.AddRange(GetAllDesktopWindows(hWnd));
            }

            return(wndParam);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取所有桌面窗体
        /// </summary>
        /// <returns></returns>
        public static WindowInfo[] GetAllDesktopWindows()
        {
            //用来保存窗口对象 列表
            List <WindowInfo> wndList = new List <WindowInfo>();

            EnumWindows(delegate(IntPtr hWnd, int lParam)
            {
                WindowInfo wnd   = new WindowInfo();
                StringBuilder sb = new StringBuilder(256);
                wnd.hWnd         = hWnd;
                GetWindowTextW(hWnd, sb, sb.Capacity);
                wnd.szWindowName = sb.ToString();
                GetClassNameW(hWnd, sb, sb.Capacity);
                wnd.szClassName = sb.ToString();
                GetWindowThreadProcessId(hWnd.ToInt32(), out wnd.ProcessId);
                //控件id
                wnd.ItemId = WindowFormAPI.GetDlgCtrlID(hWnd);
                //父句柄
                wnd.FatherhWnd = WindowFormAPI.GetParent(hWnd);
                wndList.Add(wnd);
                return(true);
            }, 0);
            return(wndList.ToArray());
        }