/// <summary> /// Sets the show state and the restored, minimized, and maximized positions of the specified window. /// </summary> /// <param name="windowHandle">A handle to the window.</param> /// <param name="placement"> /// A pointer to the <see cref="WindowPlacement" /> structure that specifies the new show state and /// window positions. /// </param> public static void SetWindowPlacement(IntPtr windowHandle, WindowPlacement placement) { // Check if the handle is valid HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle"); // If the debugger is attached and the state of the window is ShowDefault, there's an issue where the window disappears if (Debugger.IsAttached && placement.ShowCmd == WindowStates.ShowNormal) { placement.ShowCmd = WindowStates.Restore; } // Set the window placement if (!NativeMethods.SetWindowPlacement(windowHandle, ref placement)) { throw new Win32Exception("Couldn't set the window placement."); } }
public static extern bool GetWindowPlacement(IntPtr hWnd, out WindowPlacement lpwndpl);