Created
November 13, 2010 04:51
-
-
Save DanielKeep/675096 to your computer and use it in GitHub Desktop.
Minecraft Resizer (for Windows)
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
# | |
# Minecraft Resizer (for Windows) | |
# Copyright (C) 2010, Daniel Keep. | |
# Licensed under the BSD <http://www.opensource.org/licenses/bsd-license.php> | |
# Canonical URL: https://gist.github.com/675096 | |
# | |
# Changelog: | |
# | |
# 2010-11-13: | |
# - Added option to center window on the primary screen. | |
# - Fixed problem with calling FindWindow. Sometimes, I just want to smack | |
# ctypes. Also fixed swapping X & Y of window position when resizing. | |
# | |
# | |
# Stuff you can edit. | |
# | |
# Select the resolution to set the Minecraft window to. Note that this script | |
# takes care to ensure the window borders are not included in this measurement. | |
# This means that if you set the resolution to your monitor resolution, the | |
# window will be larger than your monitor can display due to the borders! | |
# Supports 480p, 720p, 1080p | |
RESOLUTION = '720p' | |
# Center on screen? (Note: centers on to your *primary* screen only.) | |
CENTER = True | |
# | |
# You shouldn't need to edit anything below here. | |
# | |
RESOLUTIONS = { | |
'480p': (720, 480), | |
'720p': (1280, 720), | |
'1080p': (1920, 1080), | |
} | |
WINDOW_WIDTH, WINDOW_HEIGHT = RESOLUTIONS[RESOLUTION] | |
# | |
# Win32 api declarations. | |
# | |
from ctypes import * | |
HWND = c_voidp | |
LPCTSTR = c_wchar_p | |
class RECT(Structure): | |
_fields_ = [('left', c_long), | |
('top', c_long), | |
('right', c_long), | |
('bottom', c_long)] | |
def ErrorIfZero(handle): | |
if handle == 0: | |
raise WinError() | |
else: | |
return handle | |
FindWindowEx = windll.user32.FindWindowExW | |
GetClientRect = windll.user32.GetClientRect | |
GetClientRect.argtypes = [HWND, POINTER(RECT)] | |
GetClientRect.restype = ErrorIfZero | |
GetWindowRect = windll.user32.GetWindowRect | |
GetWindowRect.argtypes = [HWND, POINTER(RECT)] | |
GetWindowRect.restype = ErrorIfZero | |
MoveWindow = windll.user32.MoveWindow | |
MoveWindow.argtypes = [HWND, c_int, c_int, c_int, c_int, c_bool] | |
MoveWindow.restype = ErrorIfZero | |
SystemParametersInfo = windll.user32.SystemParametersInfoW | |
SPI_GETWORKAREA = 0x0030 | |
MessageBox = windll.user32.MessageBoxW | |
MessageBox.argtypes = [HWND, LPCTSTR, LPCTSTR, c_uint] | |
MB_OK = 0x00000000 | |
MB_ICONASTERISK = 0x00000020 | |
MINECRAFT_WND_TITLE = (u"Minecraft", u"Minecraft Launcher") | |
MINECRAFT_WND_CLASS = u"SunAwtFrame" | |
# | |
# Do the resize. | |
# | |
hwnd = None | |
for title in MINECRAFT_WND_TITLE: | |
hwnd = FindWindowEx(0, 0, MINECRAFT_WND_CLASS, title) | |
if hwnd: break | |
if not hwnd: | |
MessageBox(None, | |
"Could not locate the Minecraft window. Is it running?", | |
"Minecraft Resizer", | |
MB_OK + MB_ICONASTERISK) | |
import sys | |
sys.exit(1) | |
crect = RECT() | |
wrect = RECT() | |
GetClientRect(hwnd, pointer(crect)) | |
GetWindowRect(hwnd, pointer(wrect)) | |
diff_w = (wrect.right-wrect.left) - (crect.right-crect.left) | |
diff_h = (wrect.bottom-wrect.top) - (crect.bottom-crect.top) | |
wnd_w = WINDOW_WIDTH + diff_w | |
wnd_h = WINDOW_HEIGHT + diff_h | |
wnd_l = wrect.left | |
wnd_t = wrect.top | |
force_repaint = True | |
if CENTER: | |
drect = RECT() | |
SystemParametersInfo(SPI_GETWORKAREA, 0, pointer(drect), 0) | |
desk_w = (drect.right-drect.left) | |
desk_h = (drect.bottom-drect.top) | |
wnd_l = (desk_w-wnd_w)//2 | |
wnd_t = (desk_h-wnd_h)//2 | |
MoveWindow(hwnd, wnd_l, wnd_t, wnd_w, wnd_h, force_repaint) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment