简体   繁体   English

在 .HTA 程序中,如何更改它在脚本中的运行图标(VBScript 或 Javascript 都可以)?

[英]In an .HTA program, how can I change it's running icon in script (either VBScript or Javascript is fine)?

I want to change the icon of a running HTA (you know, the little icon that's in the upper left corner of the window and is on the task bar while it's running) from inside itself during runtime (so very likely using VBScript or JavaScript).我想在运行时从内部更改正在运行的 HTA 的图标(你知道,窗口左上角的小图标,它在运行时位于任务栏上)(很可能使用 VBScript 或 JavaScript) . How can I go about doing doing that?我该怎么做呢?

(Just so we're clear, since Googling for this problem gives me all the wrong answers: What i'm NOT trying to do is change the icon of the .hta file itself when looked at in Explorer, and I'm not trying to create a shortcut to anything with a particular icon. I want to have an HTA arbitrarily change it's own running icon any time while it's running.) (我们很清楚,因为谷歌搜索这个问题给了我所有错误的答案:我不想做的是在资源管理器中查看时更改 .hta 文件本身的图标,我没有尝试为具有特定图标的任何内容创建快捷方式。我希望 HTA 在运行时随时更改它自己的运行图标。)

It feels like it'd be something simple that I just can't find.感觉就像我找不到的简单的东西。

I've already tried setting (my HTA application object) .Icon, and although it doesn't throw an error, and I can even read the property and it'll show the new value, the actual icon doesn't change.我已经尝试过设置(我的 HTA 应用程序对象) .Icon,虽然它不会引发错误,而且我什至可以读取属性并且它会显示新值,但实际图标不会改变。

When in doubt, read the documentation :如有疑问,请阅读文档

Remarks评论

Note The icon property is read-only;注意icon属性是只读的; however, the ICON attribute can be used to set the initial value.但是,可以使用ICON属性设置初始值。

Basically, what you're asking is not possible.基本上,你问的是不可能的。

Even though you can change the attribute at run time that doesn't change the actual icon in the titlebar:即使您可以在运行时更改不会更改标题栏中实际图标的属性:

<html>
<hta:application id="oHTA"
    icon="C:\path\to\some.ico"
/>
<script language="VBScript">
Sub ChangeIcon
    MsgBox oHTA.icon  'output: C:\path\to\some.ico
    oHTA.icon = "C:\path\to\other.ico"
    MsgBox oHTA.icon  'output: C:\path\to\other.ico
    'icon in titlebar still remains the same, b/c only the attribute was updated!
End Sub
</script>
<body>
<p><input id="foo" type="button" value="Change Icon" onClick="ChangeIcon"></p>
</body>
</html>

I am 3 years late.我晚了3年。 But this answer is for anyone coming from google search results.但这个答案适用于来自谷歌搜索结果的任何人。

There are 2 steps to this process.此过程有 2 个步骤。 Number 1 is within the <hta:application section, you need: icon="#"数字 1 在 <hta:application 部分内,您需要: icon="#"

Then you need to copy the .ico file to the beginning of the HTA file, in binary format.然后您需要将 .ico 文件以二进制格式复制到 HTA 文件的开头。 You can do this from the command prompt with this command: copy /b favicon.ico+myhta.hta myhta_new.hta The output file myhta_new.hta will have a top line of binary text but this will be used by the hta file as an embedded icon.您可以使用以下命令从命令提示符执行此操作: 复制 /b favicon.ico+myhta.hta myhta_new.hta 输出文件 myhta_new.hta 将有一个二进制文本的顶行,但这将被 hta 文件用作嵌入式图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM