Binarysharp.MemoryManagement.Windows.WindowCore.SetForegroundWindow C# (CSharp) Method

SetForegroundWindow() public static method

Brings the thread that created the specified window into the foreground and activates the window. The window is restored if minimized. Performs no action if the window is already activated.
public static SetForegroundWindow ( IntPtr windowHandle ) : void
windowHandle System.IntPtr A handle to the window that should be activated and brought to the foreground.
return void
        public static void SetForegroundWindow(IntPtr windowHandle)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");

            // If the window is already activated, do nothing
            if (GetForegroundWindow() == windowHandle)
                return;

            // Restore the window if minimized
            ShowWindow(windowHandle, WindowStates.Restore);

            // Activate the window
            if(!NativeMethods.SetForegroundWindow(windowHandle))
                throw new ApplicationException("Couldn't set the window to foreground.");
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Activates the window.
 /// </summary>
 public void Activate()
 {
     WindowCore.SetForegroundWindow(Handle);
 }