Skip to content

Instantly share code, notes, and snippets.

@miau
Created September 4, 2010 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miau/565417 to your computer and use it in GitHub Desktop.
Save miau/565417 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# マウスポインタ配下にあるコントロールの幅を広げるスクリプト。
#
# 対象のコントロールにマウスポインタを置いて、ランチャーやショートカットでこのスクリプトを起動してください。
from ctypes import *
from ctypes.wintypes import *
def get_title(hwnd):
u"ウィンドウタイトル取得"
title = create_unicode_buffer(255)
windll.user32.GetWindowTextW(hwnd, title, sizeof(title))
return title.value.encode('utf-8')
# マウスポジション取得
point = POINT()
windll.user32.GetCursorPos(pointer(point))
print "mouse position: (%d, %d)" % (point.x, point.y)
# マウス配下のウィンドウ取得
hwnd = windll.user32.WindowFromPoint(point)
print 'target window(%d): "%s"' % (hwnd, get_title(hwnd))
while(1):
# 親ウィンドウ取得
hwnd_parent = windll.user32.GetAncestor(hwnd, 1) # 1: GA_PARENT
print 'parent window(%d): "%s"' % (hwnd_parent, get_title(hwnd_parent))
if hwnd_parent == hwnd or hwnd_parent == 0:
break
# 対象ウィンドウの位置(スクリーン座標)を取得
rect = RECT()
windll.user32.GetWindowRect(hwnd, pointer(rect))
print "\t(%d, %d)-(%d, %d)" % (rect.left, rect.top, rect.right, rect.bottom)
# スクリーン座標を親ウィンドウのクライアント座標に変換する
Points = POINT * 2
points = Points(
POINT(rect.left, rect.top),
POINT(rect.right, rect.bottom),
)
windll.user32.MapWindowPoints(0, hwnd_parent, points, 2)
left, top, right, bottom = points[0].x, points[0].y, points[1].x, points[1].y
# ウィンドウの横幅を 800 pixel 増やす
print "\tMoveWindow(%d):" % hwnd,
print windll.user32.MoveWindow(hwnd, left, top, right - left + 800, bottom - top, 1)
# 親ウィンドウについて同様の処理を続ける
# (親ウィンドウが狭いままだと、結局コントロールが見えないので)
hwnd = hwnd_parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment