jump to navigation

AutoHotkeyでウィンドウリサイズ他

2009-11-01 11:41 Posted by
nase
in : プログラミング
pc_green.jpg

これまでAutoHotkeyはほとんどキー操作周りでしか使っていなかったんですが、メニュー表示もできるようなので常駐ソフトを減らすために試してみました。

ウィンドウタイトルバー右端のボタンあたりで右クリックするとメニューが表示されます。

ahk_winm.gif
ウィンドウマネージメント用メニュー

AutoHotkeyソース

以下、実装。

;ウィンドウ中央寄せ関数
moveToCenter(h){
    WinGetPos, , , , tbHeight, ahk_class Shell_TrayWnd
    WinGetPos, , , wWidth, wHeight, ahk_id %h%
    XPos := (A_ScreenWidth / 2) - (wWidth / 2)
    YPos := ((A_ScreenHeight - tbHeight) / 2) - (wHeight / 2)
    WinMove ahk_id %h%,, XPos, YPos
}
;ウィンドウ上下左右半画面最大化関数
halfMaximizeToSide(h, position){
    WinGetPos, , , , tbHeight, ahk_class Shell_TrayWnd
    vWinWidth := A_ScreenWidth
    hWinWidth := A_ScreenWidth / 2
    vWinHeight := (A_ScreenHeight - tbHeight) / 2
    hWinHeight := A_ScreenHeight - tbHeight
    if (position == "t")
    {
        WinMove ahk_id %h%,, 0, 0, %vWinWidth%, %vWinHeight%
    }
    else if (position == "b")
    {
        WinMove ahk_id %h%,, 0, %vWinHeight%, %vWinWidth%, %vWinHeight%
    }
    else if (position == "l")
    {
        WinMove ahk_id %h%,, 0, 0, %hWinWidth%, %hWinHeight%
    }
    else if (position == "r")
    {
        WinMove ahk_id %h%,, %hWinWidth%, 0, %hWinWidth%, %hWinHeight%
    }
}
;タイトルバー右端ボタン位置の右クリックでリサイズ・センタリングメニュー
~RButton::
    CoordMode,Mouse,Screen
    MouseGetPos, x, y, h
    SendMessage,0x84,0,% x|y<<16,,ahk_id %h%
    if(((ErrorLevel=8) || (ErrorLevel=9) || (ErrorLevel=20)) && WinActive("ahk_id " . h)){
        Menu, resizeMenu, add, 1024x768, resizeTo1024x768
        Menu, resizeMenu, add, 800x600, resizeTo800x600
        Menu, resizeMenu, add, halfMaximize_T
        Menu, resizeMenu, add, halfMaximize_B
        Menu, resizeMenu, add, halfMaximize_L
        Menu, resizeMenu, add, halfMaximize_R
        Menu, resizeMenu, add, Centering
        Menu, resizeMenu, add, Floating
        Menu, resizeMenu, show
        return
        resizeTo1024x768:
            WinMove ahk_id %h%, , , ,1024, 768
            moveToCenter(h)
            return
        resizeTo800x600:
            WinMove ahk_id %h%, , , ,800, 600
            moveToCenter(h)
            return
        halfMaximize_T:
            halfMaximizeToSide(h,"t")
            return
        halfMaximize_B:
            halfMaximizeToSide(h,"b")
            return
        halfMaximize_L:
            halfMaximizeToSide(h,"l")
            return
        halfMaximize_R:
            halfMaximizeToSide(h,"r")
            return
        centering:
            moveToCenter(h)
            return
        floating:
            ;常時最前面表示トグル
            WinSet, Topmost, TOGGLE, ahk_id %h%
            Menu, resizeMenu, ToggleCheck, Floating
            return
    }
return

AutoHotkeyは本当に便利。

Comments»

no comments yet


*Comments and trackbacks will appear after it is approved by the administrator.