Exemple #1
0
        /// <summary>
        /// Finds the specified window by its Process ID. Then brings it to
        /// the foreground.
        /// </summary>
        /// <param name="_hWnd">Handle to the window to find and activate.</param>
        public static void ActivateWindowByHandle(uint _hWnd)
        {
            WindowPlacement windowPlacement;

            GetWindowPlacement(_hWnd, out windowPlacement);

            switch ((ShowWindowFlags)windowPlacement.showCmd)
            {
            case ShowWindowFlags.Hide: //Window is hidden
                ShowWindow((IntPtr)_hWnd, ShowWindowFlags.Restore);
                break;

            case ShowWindowFlags.ShowMinimized: //Window is minimized
                // if the window is minimized, then we need to restore it to its
                // previous size. we also take into account whether it was
                // previously maximized.
                ShowWindowFlags showCmd = (windowPlacement.flags == WPF_RESTORETOMAXIMIZED)
                                      ? ShowWindowFlags.ShowMaximized
                                      : ShowWindowFlags.ShowNormal;
                ShowWindow((IntPtr)_hWnd, showCmd);
                break;

            default:
                // if it's not minimized, then we just call SetForegroundWindow to
                // bring it to the front.
                SetForegroundWindow((IntPtr)_hWnd);
                break;
            }
        }
Exemple #2
0
    public async Task ShowWindowAsync(IWindowControl windowContent, ShowWindowFlags flags = ShowWindowFlags.None, params string[] groupNames)
    {
        var openWindowInstance = new OpenWindowInstance(new WeakReference <IWindowControl>(windowContent), groupNames);

        try
        {
            // Remove instances which have been collected by the GC
            OpenWindows.RemoveWhere(x => !x.Window.TryGetTarget(out _));

            Type contentType = windowContent.UIContent.GetType();

            IWindowControl blockingWindow = OpenWindows.
                                            Select(x => x.Window.TryGetTarget(out IWindowControl w) ? new { Window = w, x.GroupNames } : null).
                                            FirstOrDefault(x =>
            {
                // Check for duplicate types
                if (!flags.HasFlag(ShowWindowFlags.DuplicateTypesAllowed) && x?.Window.UIContent.GetType() == contentType)
                {
                    return(true);
                }

                // Check for duplicate group names
                if (groupNames.Any() && x?.GroupNames.Any(groupNames.Contains) == true)
                {
                    return(true);
                }

                return(false);
            })?.Window;

            // If there is a window blocking this one from showing we return
            if (blockingWindow != null)
            {
                Logger.Info("The window is not being shown due to a window of the same type or ID being available", contentType);

                // Focus the blocking window
                if (!flags.HasFlag(ShowWindowFlags.DoNotFocusBlockingWindow))
                {
                    blockingWindow.WindowInstance?.Focus();
                }

                return;
            }

            OpenWindows.Add(openWindowInstance);

            // Show the window
            await ShowWindowAsync(windowContent, false, null);
        }
        finally
        {
            OpenWindows.Remove(openWindowInstance);

            windowContent.Dispose();
        }
    }
 public bool ShowAsync(ShowWindowFlags viewMode)
 {
     return(WinWindowUtility.ShowWindowAsync(this.Handle, viewMode));
 }
Exemple #4
0
 public static extern uint ShowWindow(IntPtr hwnd, ShowWindowFlags showCommand);
Exemple #5
0
 public static extern IntPtr GetWindow(IntPtr hwnd, ShowWindowFlags wCmd);
 public static extern uint ShowWindow(IntPtr hwnd, ShowWindowFlags showCommand);
Exemple #7
0
 public static extern IntPtr ShowWindow(IntPtr handle, ShowWindowFlags command);
Exemple #8
0
 public static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags nCmdShow);
Exemple #9
0
 private static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags nCmdShow);
Exemple #10
0
 public static extern IntPtr GetWindow(IntPtr hwnd, ShowWindowFlags wCmd);
 private static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags nCmdShow);
Exemple #12
0
 public static extern bool ShowWindow(IntPtr handle, ShowWindowFlags showCommand);
Exemple #13
0
 public static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags flags);
Exemple #14
0
 public static extern bool ShowWindowAsync(IntPtr hWnd, ShowWindowFlags nCmdShow);
Exemple #15
0
 public static extern int ShowWindow(IntPtr hWnd, ShowWindowFlags nCmdShow);