Skip to content

Instantly share code, notes, and snippets.

@coldnebo
Created August 16, 2011 02:39
Show Gist options
  • Save coldnebo/1148334 to your computer and use it in GitHub Desktop.
Save coldnebo/1148334 to your computer and use it in GitHub Desktop.
win7 powershell script to automatically resize a minecraft window for 1280x720 HD fraps recording.
# Win7 Powershell script to resize Minecraft to 1280x720 (HD for fraps youtube capture)
# use by typing the following at a command prompt:
# > PowerShell -ExecutionPolicy Bypass -File minecraft-sethd.ps1
# refs:
# http://stackoverflow.com/questions/2556872/how-to-set-foreground-window-from-powershell-event-subscriber-action
# http://richardspowershellblog.wordpress.com/2011/07/23/moving-windows/
# http://www.suite101.com/content/client-area-size-with-movewindow-a17846
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
$rcWindow = New-Object RECT
$rcClient = New-Object RECT
$h = (Get-Process | where {$_.MainWindowTitle -eq "minecraft"}).MainWindowHandle
[Win32]::GetWindowRect($h,[ref]$rcWindow)
[Win32]::GetClientRect($h,[ref]$rcClient)
$width = 1280
$height = 720
$dx = ($rcWindow.Right - $rcWindow.Left) - $rcClient.Right
$dy = ($rcWindow.Bottom - $rcWindow.Top) - $rcClient.Bottom
[Win32]::MoveWindow($h, $rct.Left, $rct.Top, $width + $dx, $height + $dy, $true )
@coldnebo
Copy link
Author

An alternative to this (if you don't mind mods and the mod is compatible with the current Minecraft) is the Single Player mod, which also contains a command for resizing the window to different HD resolutions: http://www.minecraftforum.net/topic/94310-173-single-player-commands-v210-2/#p1494675

Copy link

ghost commented Dec 3, 2012

Thank you so much for this, works like a charm!

@Kzitold
Copy link

Kzitold commented Oct 5, 2016

Does this work with multi-monitor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment