指定されたウィンドウの形状を、指定された矩形、楕円、多角形のいずれかに変更します。
WinSetRegion Options, WinTitle, WinText, ExcludeTitle, ExcludeText
型:文字列
空白または省略された場合、ウィンドウは元の/デフォルトの表示領域に戻される。Otherwise, specify one or more of the following options, each separated from the others with space(s):
Wn:Width of rectangle or ellipse. 事例:w200
.
Hn:Height of rectangle or ellipse. 事例:h200
.
X-Y:それぞれX/Y座標のペア。例えば、200-0
は、X座標に200、Y座標に0を使う。
E:領域を矩形ではなく楕円にする。This option is valid only when W and H are present.
Rw-h: Makes the region a rectangle with rounded corners. For example, r30-30
would use a 30x30 ellipse for each corner. If w-h is omitted, 30-30 is used. R is valid only when W and H are present.
Rectangle or ellipse: If the W and H options are present, the new display area will be a rectangle whose upper left corner is specified by the first (and only) pair of X-Y coordinates. However, if the E option is also present, the new display area will be an ellipse rather than a rectangle. 事例:WinSetRegion "50-0 w200 h250 E"
.
Polygon: When the W and H options are absent, the new display area will be a polygon determined by multiple pairs of X-Y coordinates (each pair of coordinates is a point inside the window relative to its upper left corner). 例えば、3組の座標が指定された場合、ほとんどの場合、新しい表示領域は三角形になる。互いに対する座標ペアの順番が重要な場合もある。In addition, the word Wind maybe be present in Options to use the winding method instead of the alternating method to determine the polygon's region.
もしこれらの項目が未設定または省略されたときは、最後に見つかったウィンドウが使用されます。そうでないときは、WinTitleに ウィンドウタイトルまたはターゲットウィンドウを識別するための他の基準、および/またはWinTextにターゲットウィンドウの単一のテキスト要素からの部分文字列(付属のWindow Spyユーティリティを使えばわかります)を指定します。
ExcludeTitleとExcludeTextはウィンドウのタイトルまたはテキストで除外するために使用します。指定の仕方はWinTitleとWinTextに似ていますが、ExcludeTitleはウィンドウのタイトル以外の基準(ウィンドウクラスやHWNDなど)を認識しません。
ウィンドウのタイトルとテキストは大文字と小文字を区別します。DetectHiddenWindows関数 と DetectHiddenText関数で変更しない限り、初期設定では非表示ウィンドウは検出されず、非表示テキストは検出されます。SetTitleMatchMode関数で変更しない限り、初期設定ではウィンドウのタイトルはその中のどこかにWinTitleまたはExcludeTitleを含んでいれば一致します。
ウィンドウが見つからないときは、TargetErrorがスローされます。
1つ以上のオプションが無効な場合、または2000組以上の座標が指定された場合、ValueErrorがスローされます。
指定された領域が無効であったり、ターゲットウィンドウに適用できなかったりすると、OSErrorがスローされる。
マウスカーソルの下にあるウィンドウのIDは、MouseGetPos関数で取得できます。
スクリプトが所有するウィンドウに領域が設定されると、システムはウィンドウのフレームをレンダリングするために使用する方法を自動的に変更し、それによってウィンドウの外観を変更することがあります。効果は以下に示す回避策#2と似ているが、ウィンドウの領域がリセットされるまでしか影響しない。
既知の制限事項:ウィンドウにキャプション(タイトルバー)があり、システムでデスクトップ合成が有効になっている場合、スクリプトが所有していないウィンドウに領域を設定すると、予期しない結果になることがあります。This is because the visible frame is not actually part of the window, but rendered by a separate system process known as Desktop Window Manager (DWM). なお、Windows 8以降では、デスクトップ合成は常に有効になっている。以下の2つの回避策のいずれかを使用することができる:
; #1: Remove the window's caption. WinSetStyle "-0xC00000", "Window Title" ; To undo it: WinSetStyle "+0xC00000", "Window Title"
; #2: Disable DWM rendering of the window's frame. DllCall("dwmapi\DwmSetWindowAttribute", "ptr", WinExist("Window Title") , "uint", DWMWA_NCRENDERING_POLICY := 2, "int*", DWMNCRP_DISABLED := 1, "uint", 4) ; To undo it (this might also cause any set region to be ignored): DllCall("dwmapi\DwmSetWindowAttribute", "ptr", WinExist("Window Title") , "uint", DWMWA_NCRENDERING_POLICY := 2, "int*", DWMNCRP_ENABLED := 2, "uint", 4)
Win functions, Control functions
この矩形の外側にあるメモ帳のすべての部分を不可視にする。この例は、Windows11以降の新しいメモ帳ではうまく動作しないかもしれません。
WinSetRegion "50-0 w200 h250", "ahk_class Notepad"
上記と同じだが、角が40x40に丸くなっている。この例は、Windows11以降の新しいメモ帳ではうまく動作しないかもしれません。
WinSetRegion "50-0 w200 h250 r40-40", "ahk_class Notepad"
矩形の代わりに楕円を作成する。この例は、Windows11以降の新しいメモ帳ではうまく動作しないかもしれません。
WinSetRegion "50-0 w200 h250 E", "ahk_class Notepad"