-
-
Save NathanielArnoldR2/775613aab37620a5745b9fc1da1988e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -TypeDefinition @" | |
using System; | |
using System.Runtime.InteropServices; | |
namespace ConsoleHostInteraction { | |
public static class WindowTricks { | |
private struct RECT { | |
public int left; | |
public int top; | |
public int right; | |
public int bottom; | |
} | |
[DllImport("user32.dll")] | |
private static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); | |
[DllImport("user32.dll")] | |
private static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); | |
[DllImport("user32.dll")] | |
private static extern int GetSystemMetrics(int smIndex); | |
public static void MoveWindowToCenter (IntPtr hWnd) { | |
RECT Rect = new RECT(); | |
GetWindowRect(hWnd, ref Rect); | |
int screenWidth = GetSystemMetrics(0); | |
int screenHeight = GetSystemMetrics(1); | |
int consoleWidth = Rect.right - Rect.left; | |
int consoleHeight = Rect.bottom - Rect.top; | |
MoveWindow(hWnd, (screenWidth / 2) - (consoleWidth / 2), (screenHeight / 2) - (consoleHeight / 2), consoleWidth, consoleHeight, true); | |
} | |
} | |
} | |
"@ | |
[ConsoleHostInteraction.WindowTricks]::MoveWindowToCenter((Get-Process -Id $PID).MainWindowHandle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment