Example #1
0
        public static List <WindowInfo> GetChildWindowsByParentHwnd(IntPtr parentHwnd)
        {
            List <WindowInfo> childWndList = new List <WindowInfo>();

            WinAPIWrapper.EnumChildWindows(parentHwnd, delegate(IntPtr hWnd, int lParam)
            {
                WindowInfo wnd   = new WindowInfo();
                StringBuilder sb = new StringBuilder(256);
                wnd.hWnd         = hWnd;
                WinAPIWrapper.GetWindowTextW(hWnd, sb, sb.Capacity);
                wnd.SzWindowName = sb.ToString();
                WinAPIWrapper.GetClassNameW(hWnd, sb, sb.Capacity);
                wnd.SzClassName = sb.ToString();
                childWndList.Add(wnd);
                return(true);
            }, 0);
            return(childWndList);
        }
Example #2
0
        /// <summary>
        /// 获取桌面所有的窗口
        /// </summary>
        /// <returns></returns>
        public static WindowInfo[] GetAllDesktopWindows()
        {
            List <WindowInfo> wndList = new List <WindowInfo>();

            WinAPIWrapper.EnumWindows(delegate(IntPtr hWnd, int lParam)
            {
                WindowInfo wnd   = new WindowInfo();
                StringBuilder sb = new StringBuilder(256);
                wnd.hWnd         = hWnd;
                WinAPIWrapper.GetWindowTextW(hWnd, sb, sb.Capacity);
                wnd.SzWindowName = sb.ToString();
                WinAPIWrapper.GetClassNameW(hWnd, sb, sb.Capacity);
                wnd.SzClassName = sb.ToString();
                wndList.Add(wnd);
                return(true);
            }, 0);
            return(wndList.ToArray());
        }