Beispiel #1
0
        private List <WindowInfo> GetOpenWindows()
        {
            var collection = new List <WindowInfo>();

            WinApi.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                var strbTitle = new StringBuilder(255);
                WinApi.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);

                var windowInfo = new WindowInfo();
                windowInfo.Handle    = hWnd;
                windowInfo.IsVisible = WinApi.IsWindowVisible(hWnd);
                windowInfo.Title     = strbTitle.ToString();
                collection.Add(windowInfo);

                return(true);
            };
            WinApi.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(collection);
        }
Beispiel #2
0
        private static Dictionary <IntPtr, string> GetAllWindows()
        {
            var collection = new Dictionary <IntPtr, string>();

            WinApi.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                if (WinApi.IsWindowVisible(hWnd))
                {
                    var strbTitle = new StringBuilder(255);
                    WinApi.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                    var strTitle = strbTitle.ToString();
                    if (!string.IsNullOrEmpty(strTitle))
                    {
                        collection[hWnd] = strTitle;
                    }
                }
                return(true);
            };
            WinApi.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(collection);
        }