示例#1
0
        public static List <WindowInfo> GetWindowByParentHwndAndClassName(IntPtr parentHwnd, string className)
        {
            List <WindowInfo> wndList = new List <WindowInfo>();

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

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