UlteriusServer.Api.Win32.Desktop.GetWindows C# (CSharp) Method

GetWindows() public method

Enumerates the windows on a desktop.
public GetWindows ( ) : WindowCollection
return WindowCollection
        public WindowCollection GetWindows()
        {
            // make sure object isnt disposed.
            CheckDisposed();

            // make sure a desktop is open.
            if (!IsOpen) return null;

            // init the arraylist.
            m_windows.Clear();
            var windows = new WindowCollection();

            // get windows.
            var result = EnumDesktopWindows(DesktopHandle, DesktopWindowsProc, IntPtr.Zero);

            // check for error.
            if (!result) return null;

            // get window names.
            windows = new WindowCollection();

            var ptr = Marshal.AllocHGlobal(MaxWindowNameLength);

            foreach (IntPtr wnd in m_windows)
            {
                GetWindowText(wnd, ptr, MaxWindowNameLength);
                windows.Add(new Window(wnd, Marshal.PtrToStringAnsi(ptr)));
            }

            Marshal.FreeHGlobal(ptr);

            return windows;
        }