コード例 #1
0
        private static bool EnumChildWindowsFunc(IntPtr hWnd, IntPtr lParam)
        {
            var info = (WindowInfo)Marshal.PtrToStructure(lParam, typeof(WindowInfo));

            LowLevel.GetWindowThreadProcessId(hWnd, out var processId);

            if (info != null && processId != info.OwnerPid)
            {
                info.ChildPid = processId;
            }

            Marshal.StructureToPtr(info, lParam, true);
            return(true);
        }
コード例 #2
0
        public IEnumerable <OpenedWindow> GetOpenedWindows()
        {
            var openedWindows = new List <OpenedWindow>();

            var filter = new EnumerateFunc((hwnd, param) =>
            {
                var buffer = new StringBuilder(255);
                LowLevel.GetWindowText(hwnd, buffer, buffer.Capacity + 1);

                var title = buffer.ToString();

                if (!LowLevel.IsWindowVisible(hwnd) || string.IsNullOrEmpty(title) || hwnd == (IntPtr)0x0)
                {
                    return(true);
                }

                LowLevel.GetWindowThreadProcessId(hwnd, out var processId);
                var executablePath = LowLevelHelper.GetUwpApplicationName(hwnd, processId);

                if (executablePath == null)
                {
                    return(true);
                }

                if (_excludedProcesses.Any(x => executablePath.Contains(x) || title.Contains(x)))
                {
                    return(true);
                }

                openedWindows.Add(new OpenedWindow
                {
                    Hwnd           = hwnd,
                    Title          = title,
                    ExecutablePath = executablePath,
                    Uid            = _hashProvider.Create(hwnd.ToString())
                });

                return(true);
            });

            LowLevel.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(openedWindows);
        }