<style type="text/css"> .sized1 { width: 20em; } .sized2 { width: 5em; } </style> </head> <body> <h1>TrayTip</h1> <p>在<a href="../Program.htm#tray-icon">托盘图标</a>附近显示一个气球提示窗口. 在 Windows 10 及后续版本中, 显示一个 toast 通知.</p> <pre class="Syntax"><span class="func">TrayTip</span> <span class="optional">Text, Title, Options</span></pre> <h2 id="Parameters">参数</h2> <dl> <dt>Text</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>如果为空或省略, 则会移除托盘提示中的文本, 这会让它垂直高度变短. 否则, 请指定请托盘提示要显示的消息. 仅显示前 256 个字符.</p> <p>可以使用回车(`r) 或换行(`n) 来创建多行文本. 例如: <code>Line1`nLine2</code>.</p> <p>如果 <em>Text</em> 较长, 可以通过<a href="../Scripts.htm#continuation">延续片段</a>的方法将其分解成较短的几行, 这样可以增加可读性和可维护性.</p> <p>可以通过留空 <em>Text</em> 来显示只有标题的窗口.</p> </dd> <dt>Title</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>如果为空或省略, 则会移除托盘提示的标题行, 这会让它垂直高度变短. 否则, 请指定托盘提示的标题. 仅显示前 73 个字符.</p> </dd> <dt>Options</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p> <p><p>如果为空或省略, 则默认为 0. 否则, 请指定一个整数值(由加法或按位或的组合), 也可以是一个由至少一个空格或制表符分隔的不区分大小写的零或多个选项字符串. 字符串中还可以包含一个或多个数字选项.</p> <table class="info"> <tr> <th class="sized1">功能</th> <th class="sized2 right">十进制值</th> <th class="sized2 right">十六进制值</th> <th>字符串</th> </tr> <tr> <td>无图标</td> <td class="right">0</td> <td class="right">0x0</td> <td>N/A</td> </tr> <tr> <td>信息图标</td> <td class="right">1</td> <td class="right">0x1</td> <td><code>Iconi</code></td> </tr> <tr> <td>警告图标</td> <td class="right">2</td> <td class="right">0x2</td> <td><code>Icon!</code></td> </tr> <tr> <td>错误图标</td> <td class="right">3</td> <td class="right">0x3</td> <td><code>Iconx</code></td> </tr> <tr> <td><a href="TraySetIcon.htm">托盘图标</a></td> <td class="right">4</td> <td class="right">0x4</td> <td>N/A</td> </tr> <tr> <td>不播放通知音.</td> <td class="right">16</td> <td class="right">0x10</td> <td><code>Mute</code></td> </tr> <tr> <td>使用大图标.</td> <td class="right">32</td> <td class="right">0x20</td> <td>N/A</td> </tr> </table> <p>如果省略 <em>Title</em>, 也不会显示图标(这不适用于 Windows 10 及后续版本的 toast 通知).</p> <p>在 Windows 10 及后续版本中, 即使省略了 "tray icon" 选项 (4), 小托盘图标通常也会显示, 并且指定该选项可能会导致程序的名称显示在通知中.</p> </dd> </dl> <h2 id="To_Hide_the_Window">隐藏窗口</h2> <p>要隐藏气球窗口, 同时省略 <em>Text</em> 和 <em>Title</em>. 例如:</p> <pre>TrayTip</pre> <p>要隐藏 Windows 10 的 toast 通知, 临时移除<a href="../Program.htm#tray-icon">托盘图标</a>. 例如:</p> <h2 id="Hiding_the_Traytip">隐藏托盘提示</h2> <p>若要隐藏托盘提示, 请省略所有参数(或至少省略 <em>Text</em> 和 <em>Title</em> 参数). 例如:</p> <pre>TrayTip</pre> <p>要在 Windows 10 上隐藏托盘提示, 临时移除<a href="../Program.htm#tray-icon">托盘图标</a>(根据至少一个报告, 这并不总是工作). 例如:</p> <pre>TrayTip "#1", "This is TrayTip #1" Sleep 3000 <em>; 让它显示 3 秒钟.</em> HideTrayTip TrayTip "#2", "This is the second notification." Sleep 3000 <em id="Hide">; 将此函数复制到脚本中使用.</em> HideTrayTip() { TrayTip <em>; 尝试以普通的方式隐藏它.</em> if SubStr(A_OSVersion,1,3) = "10." { A_IconHidden := true Sleep 200 <em>; 可能有必要调整 sleep 的时间.</em> A_IconHidden := false } } </pre> <h2 id="Remarks">备注</h2> <p>在 Windows 10 中, 托盘提示窗口通常是这样的:</p> <img src="../static/dlg_traytip.png" alt="TrayTip" /> <p id="Windows10"><strong>Windows 10 及后续版本</strong> 默认以 toast 通知替换气球提示窗口(这能被重置通过主策略). TrayTip 多次调用通常会导致多个通知被放置在一个 "队列" 而不是每个通知取代最近的那个.</p> <p>如果脚本没有<a href="../Program.htm#tray-icon">托盘图标</a>(使用 <a href="_NoTrayIcon.htm">#NoTrayIcon</a> 或 <code><a href="../Variables.htm#IconHidden">A_IconHidden</a> := true</code>), 则 TrayTip 没有效果. 同样地, 如果下列的 REG_DWORD 值存在且被设置为 0, 则 TrayTip 没有效果:</p> <pre>HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced &gt;&gt; EnableBalloonTips</pre> <p>相关提示, 每当用户把鼠标悬停在脚本<a href="../Program.htm#tray-icon">托盘图标</a>上时会显示工具提示. 此工具提示的内容可以使用这样的方法改变: <code><a href="../Variables.htm#IconTip">A_IconTip</a> := "My New Text"</code>.</p> <h2 id="Related">相关</h2> <p><a href="ToolTip.htm">ToolTip</a>, <a href="SetTimer.htm">SetTimer</a>, <a href="Menu.htm">Menu 对象</a>, <a href="MsgBox.htm">MsgBox</a>, <a href="InputBox.htm">InputBox</a>, <a href="FileSelect.htm">FileSelect</a>, <a href="DirSelect.htm">DirSelect</a></p> <h2 id="Examples">示例</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> 在<a href="../Program.htm#tray-icon">托盘图标</a>附近显示多行气球消息或 toast 通知 20 秒, 而不播放通知声音. 它也有一个标题并包含一个信息图标.</p> <pre>TrayTip "Multiline`nText", "My Title", "Iconi Mute"</pre> </div> <div class="ex" id="ExDisplayTime"> <p><a class="ex_number" href="#ExDisplayTime"></a> 提供更精确的控制显示的时间, 没有使用 Sleep(它会停止当前线程).</p> <pre>TrayTip "This will be displayed for 5 seconds.", "Timed traytip" SetTimer () =&gt; TrayTip(), -5000</pre> <p>下面的代码也有同样的功能, 但可以用<a href="#Hide">上面</a>为 Windows 10 定义的 HideTrayTip 函数来替换.</p> <pre> TrayTip "This will be displayed for 5 seconds.", "Timed traytip" SetTimer HideTrayTip, -5000 HideTrayTip() { TrayTip } </pre> </div> <div class="ex" id="ExPermanent"> <p><a class="ex_number" href="#ExPermanent"></a> 通过定时器定期刷新, 永久显示托盘提示. 注意: 由于<a href="#Windows10">上述原因</a>, 这在 Windows 10 及后续版本中可能无法正常工作.</p> <pre>#Persistent SetTimer RefreshTrayTip, 1000 RefreshTrayTip <em>; 调用一次来让它立即开始.</em> RefreshTrayTip() { TrayTip "This is a more permanent traytip.", "Refreshed traytip", "Mute" }</pre> </div> </body> </html>