Created
January 21, 2025 17:24
-
-
Save jbratu/33e69dc2f05f2f8127a456469d3c011f 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
#Run this script with | |
#cd ([Environment]::GetFolderPath("Desktop") | |
#powershell.exe -ExecutionPolicy Bypass -File "srp editor side by side.ps1" | |
# Load required assemblies | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
# Add Windows API functions | |
Add-Type @" | |
using System; | |
using System.Runtime.InteropServices; | |
public class Win32 { | |
[DllImport("user32.dll", SetLastError = true)] | |
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); | |
[DllImport("user32.dll", SetLastError = true)] | |
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); | |
[DllImport("user32.dll")] | |
public static extern IntPtr GetForegroundWindow(); | |
[DllImport("user32.dll")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); | |
[StructLayout(LayoutKind.Sequential)] | |
public struct RECT { | |
public int Left; | |
public int Top; | |
public int Right; | |
public int Bottom; | |
} | |
} | |
"@ | |
Write-Host "Script started..." | |
Write-Host "Getting screen dimensions..." | |
# Get screen dimensions | |
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds | |
Write-Host "Screen dimensions: Width=$($screen.Width), Height=$($screen.Height)" | |
Write-Host "`nSearching for processes with windows..." | |
# List all processes with window titles for debugging | |
$allWindows = Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | |
Write-Host "Found $($allWindows.Count) total windows with titles:" | |
$allWindows | ForEach-Object { | |
Write-Host " - '$($_.MainWindowTitle)'" | |
} | |
Write-Host "`nFiltering for 'SRP Editor - ' windows..." | |
# Find windows that start with "SRP Editor - " | |
$windows = Get-Process | Where-Object {$_.MainWindowTitle -like "SRP Editor*"} | | |
Select-Object MainWindowHandle, MainWindowTitle | |
Write-Host "Found $($windows.Count) SRP Editor windows:" | |
$windows | ForEach-Object { | |
Write-Host " - '$($_.MainWindowTitle)'" | |
} | |
# Check if we found at least two SRP Editor windows | |
if ($windows.Count -lt 2) { | |
Write-Host "`nError: Could not find two SRP Editor windows. Found $($windows.Count) window(s)." | |
exit | |
} | |
# Process first two SRP Editor windows | |
for ($i = 0; $i -lt 2; $i++) { | |
$window = $windows[$i] | |
$hwnd = $window.MainWindowHandle | |
Write-Host "`nProcessing window: '$($window.MainWindowTitle)'" | |
Write-Host "Window handle: $hwnd" | |
# Ensure window is not minimized | |
Write-Host "Restoring window if minimized..." | |
[Win32]::ShowWindow($hwnd, 1) # SW_NORMAL = 1 | |
# Calculate new position | |
if ($i -eq 0) { | |
# Left half | |
$x = 0 | |
$width = $screen.Width / 2 | |
Write-Host "Calculated left position: x=$x, width=$width" | |
} else { | |
# Right half | |
$x = $screen.Width / 2 | |
$width = $screen.Width / 2 | |
Write-Host "Calculated right position: x=$x, width=$width" | |
} | |
# Calculate height leaving 200 pixels at bottom | |
$height = $screen.Height - 200 | |
Write-Host "Calculated height: $height" | |
# Move and resize window | |
Write-Host "Attempting to move and resize window..." | |
$result = [Win32]::MoveWindow($hwnd, $x, 0, $width, $height, $true) | |
Write-Host "MoveWindow result: $result" | |
$position = if ($i -eq 0) { 'left' } else { 'right' } | |
Write-Host "Positioned window '$($window.MainWindowTitle)' to $position half" | |
} | |
Write-Host "`nWindow arrangement complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment