コード例 #1
0
ファイル: Dawsome.cs プロジェクト: nikku/dawsome
        private IntPtr DoForTopmostWindowForWorkspace(Workspace workspace, Action<WindowBase> action)
        {
            var window = topmostWindows[workspace.id - 1];
            if (window == null || !NativeMethods.IsWindowVisible(window.hWnd) || NativeMethods.IsIconic(window.hWnd) || workspace.GetWindow(window.hWnd) == null)
            {
                NativeMethods.EnumWindows((hWnd, _) =>
                    {
                        if (!Utilities.IsAppWindow(hWnd) || NativeMethods.IsIconic(hWnd))
                        {
                            return true;
                        }
                        if ((topmostWindows[workspace.id - 1] = workspace.GetWindow(hWnd)) != null)
                        {
                            // the workspace contains this window so make it the topmost one
                            return false;
                        }
                        if ((Utilities.IsAltTabWindow(hWnd) && !applications.ContainsKey(hWnd)) ||
                            workspace.Monitor.temporarilyShownWindows.Contains(hWnd))
                        {
                            // the window is not a managed-by-another-visible-workspace one so make it the topmost one
                            topmostWindows[workspace.id - 1] = new WindowBase(hWnd);
                            return false;
                        }
                        return true;
                    }, IntPtr.Zero);

                if (topmostWindows[workspace.id - 1] == null)
                {
                    topmostWindows[workspace.id - 1] = new WindowBase(NativeMethods.shellWindow);
                }

                window = topmostWindows[workspace.id - 1];
            }

            action(window);

            return window.hWnd;
        }