WinMove

指定したウィンドウの位置や大きさを変更します。

WinMove X, Y, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText

パラメータ

X, Y

型:整数

If either is omitted, the position in that dimension will not be changed. Otherwise, specify the X and Y coordinates (in pixels) of the upper left corner of the target window's new location. 画面左上のピクセルは0, 0にある。

幅、高さ

型:整数

If either is omitted, the size in that dimension will not be changed. Otherwise, specify the new width and height of the window (in pixels).

WinTitle、WinText、ExcludeTitle、ExcludeText

型:文字列整数またはオブジェクト

もしこれらの項目が未設定または省略されたときは、最後に見つかったウィンドウが使用されます。そうでないときは、WinTitleウィンドウタイトルまたはターゲットウィンドウを識別するための他の基準、および/またはWinTextにターゲットウィンドウの単一のテキスト要素からの部分文字列(付属のWindow Spyユーティリティを使えばわかります)を指定します。

ExcludeTitleExcludeTextはウィンドウのタイトルまたはテキストで除外するために使用します。指定の仕方はWinTitleWinTextに似ていますが、ExcludeTitleはウィンドウのタイトル以外の基準(ウィンドウクラスやHWNDなど)を認識しません。

ウィンドウのタイトルとテキストは大文字と小文字を区別します。DetectHiddenWindows関数 と DetectHiddenText関数で変更しない限り、初期設定では非表示ウィンドウは検出されず、非表示テキストは検出されます。SetTitleMatchMode関数で変更しない限り、初期設定ではウィンドウのタイトルはその中のどこかにWinTitleまたはExcludeTitleを含んでいれば一致します。

エラー処理

ウィンドウが見つからないときは、TargetErrorがスローされます。

内部関数呼び出しが失敗を報告した場合、OSErrorがスローされる。しかし、ウィンドウが自身の動きを制限している場合など、ウィンドウが動いていなくても成功が報告されることがある。

備考

If Width or Height is small (or negative), most windows with a title bar will generally go no smaller than 112 x 27 pixels (however, some types of windows may have a different minimum size). If Width or Height is large, most windows will go no larger than approximately 12 pixels beyond the dimensions of the desktop.

Negative X and Y coordinates are allowed to support multi-monitor systems and to move a window entirely off-screen.

WinMoveは最小化されたウィンドウを移動することはできませんが、DetectHiddenWindowsがオンの場合、隠されたウィンドウを移動することができます。

WinMoveの速度はSetWinDelayの影響を受ける。

異なるDPI設定を持つ複数のスクリーンを持つシステムでは、OSのDPIスケーリングにより、ウィンドウの最終的な位置とサイズが要求された値と異なる場合があります。

ControlMove, WinGetPos, WinHide, WinMinimize, WinMaximize, Win functions

電卓を開き、電卓が存在するまで待ち、画面の左上隅に移動する。

Run "calc.exe"
WinWait "Calculator"
WinMove 0, 0 ; Use the window found by WinWait.

クリップボードの内容を表示する固定サイズのポップアップウィンドウを作成し、画面の左上隅に移動する。

MyGui := Gui("ToolWindow -Sysmenu Disabled", "The clipboard contains:")
MyGui.Add("Text",, A_Clipboard)
MyGui.Show("w400 h300")
WinMove 0, 0,,, MyGui
MsgBox "Press OK to dismiss the popup window"
MyGui.Destroy()

画面上のウィンドウを中央に配置する。

CenterWindow("ahk_class Notepad")

CenterWindow(WinTitle)
{
    WinGetPos ,, &Width, &Height, WinTitle
    WinMove (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2),,, WinTitle
}