<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1632085368384154" crossorigin="anonymous"></script><script src="https://autohotkey.top/gtag.js"></script></head> <body> <h1>WinSetRegion</h1> <p>将指定窗口的形状改为指定的矩形, 椭圆或多边形.</p> <pre class="Syntax"><span class="func">WinSetRegion</span> <span class="optional">Options, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre> <h2 id="Parameters">参数</h2> <dl> <dt>Options</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>如果为空或省略, 则窗口恢复到其原始/默认显示形状. 否则, 可指定以下一个或多个选项, 每个选项之间用空格分隔:</p> <p><strong>Wn</strong>: 矩形或椭圆的宽度. 例如: <code>w200</code>.</p> <p><strong>Hn</strong>: 矩形或椭圆的高度. 例如: <code>h200</code>.</p> <p><strong>X-Y</strong>: 每一个都是一对 X/Y 坐标. 例如, <code>200-0</code> 将使用 200 作为 X 坐标, 0 作为 Y 坐标.</p> <p><strong>E</strong>: 设置窗口形状为椭圆形而不是矩形. 此选项仅在同时指定了 <strong>W</strong> 和 <strong>H</strong> 时才有效.</p> <p><strong>R[w-h]</strong>: 设置窗口形状为圆角矩形. 例如, <code>R30-30</code> 表示每个角为 30x30 的椭圆. 如果 <strong>w-h</strong> 省略, 则使用 30-30. <strong>R</strong> 仅在同时指定了 <strong>W</strong> 和 <strong>H</strong> 时才有效.</p> <p><strong>矩形或椭圆形</strong>: 如果指定了 <strong>W</strong> 和 <strong>H</strong> 选项, 那么会设置新显示的局域为矩形, 且其左上角的坐标为首个(且唯一) <strong>X-Y</strong> 坐标对. 但是, 如果同时指定了 <strong>E</strong> 选项, 那么会设置窗口形状为椭圆形而不是矩形. 例如: <code>WinSetRegion "50-0 W200 H250 E", <i>WinTitle</i></code>.</p> <p><strong>多边形</strong>: 如果 <strong>W</strong> 和 <strong>H</strong> 选项都不存在时, 新的显示区域将是由多个 <strong>X-Y</strong> 坐标对决定的多边形(每对坐标是窗口内相对于其左上角的一个点). 例如, 如果指定了三对坐标, 那么在多数时候窗口形状会被设置为三角形. 坐标对彼此间的相对顺序有时很重要. 此外, 可以在 <em>Options</em> 中指定单词 <strong>Wind</strong> 从而使用缠绕法代替变换方法来确定多边形的形状.</p> </dd> <dt>WinTitle</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p> <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p> </dd> <dt>WinText</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p> </dd> <dt>ExcludeTitle</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>标题中含有此参数值的窗口将被排除.</p> </dd> <dt>ExcludeText</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>文本中含有此参数值的窗口将被排除.</p> </dd> </dl> <h2 id="Error_Handling">错误处理</h2> <p>如果找不到窗口, 则抛出 <a href="../objects/Error.htm#TargetError">TargetError</a>.</p> <p>如果一个或多个 <em>Options</em> 无效, 或指定的坐标超过 2000 对, 则抛出 <a href="../objects/Error.htm#ValueError">ValueError</a>.</p> <p>如果指定的区域无效或无法应用于目标窗口, 则抛出 <a href="../objects/Error.htm#OSError">OSError</a>.</p> <h2 id="Remarks">备注</h2> <p>鼠标光标下的窗口的 ID 可以使用 <a href="MouseGetPos.htm">MouseGetPos</a> 来获取.</p> <p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p> <p>当为脚本所拥有的窗口设置了一个区域时, 系统可能会自动改变渲染窗口框架的方法, 从而改变其外观. 其效果类似于下面所示的解决方法 #2, 但只影响窗口, 直到其区域被重置.</p> <p><strong>已知限制</strong>: 为不属于脚本的窗口设置一个区域可能会产生意想不到的结果, 如果该窗口有标题(标题栏), 并且系统启用了桌面合成. 这是因为可见的框架实际上并不是窗口的一部分, 而是由一个名为 "桌面窗口管理器" 的单独系统进程渲染的. 注意, 在 Windows 8 及以后的版本中, 桌面合成<a href="https://docs.microsoft.com/en-us/windows/compatibility/desktop-window-manager-is-always-on">始终处于启用状态</a>. 可以使用以下两种解决方法之一:</p> <pre><em>; #1: 移除窗口标题.</em> WinSetStyle "-0xC00000", "Window Title" <em>; 恢复:</em> WinSetStyle "+0xC00000", "Window Title"</pre> <pre><em>; #2: 禁用 DWM 渲染窗口的框架.</em> DllCall("dwmapi\DwmSetWindowAttribute", "ptr", WinExist("Window Title") , "uint", DWMWA_NCRENDERING_POLICY := 2, "int*", DWMNCRP_DISABLED := 1, "uint", 4) <em>; 恢复(这也可能导致任何设置的区域被忽略):</em> DllCall("dwmapi\DwmSetWindowAttribute", "ptr", WinExist("Window Title") , "uint", DWMWA_NCRENDERING_POLICY := 2, "int*", DWMNCRP_ENABLED := 2, "uint", 4) </pre> <h2 id="Related">相关</h2> <p><a href="Win.htm">Win 函数</a>, <a href="Control.htm">Control 函数</a></p> <h2 id="Examples">示例</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> 使记事本在此矩形之外的所有部分都不可见.</p> <pre>WinSetRegion "50-0 W200 H250", "ahk_class Notepad"</pre> </div> <div class="ex" id="ExRounded"> <p><a class="ex_number" href="#ExRounded"></a> 与上面相同, 不过带有 40x40 的圆角.</p> <pre>WinSetRegion "50-0 W200 H250 R40-40", "ahk_class Notepad"</pre> </div> <div class="ex" id="ExEllipse"> <p><a class="ex_number" href="#ExEllipse"></a> 创建椭圆形窗口.</p> <pre>WinSetRegion "50-0 W200 H250 E", "ahk_class Notepad"</pre> </div> <div class="ex" id="ExTriangle"> <p><a class="ex_number" href="#ExTriangle"></a> 创建倒三角形窗口.</p> <pre>WinSetRegion "50-0 250-0 150-250", "ahk_class Notepad"</pre> </div> <div class="ex" id="ExRestore"> <p><a class="ex_number" href="#ExRestore"></a> 将窗口恢复原来/默认的形状.</p> <pre>WinSetRegion , "ahk_class Notepad"</pre> </div> <div class="ex" id="ExAdvanced"> <p><a class="ex_number" href="#ExAdvanced"></a> 它在记事本(或任何其他窗口) 内创建一个透明的矩形孔. 下面指定了两个矩形: 一个外部的, 一个内部的. 每个矩形由 5 对 X/Y 坐标组成, 因为第一对是用来 "闭合" 每个矩形的重复坐标.</p> <pre>WinSetRegion "0-0 300-0 300-300 0-300 0-0 100-100 200-100 200-200 100-200 100-100", "ahk_class Notepad"</pre> </div> <a href="https://dftg.net">dftg</a></body> </html>