如何在 HTA 中获取文件的关联图标(HTML/Javascript/VBScript)

发布于 2024-12-01 15:06:01 字数 788 浏览 2 评论 0原文

我正在构建一个 HTA 应用程序,需要在其中显示文件列表及其关联的系统图标。
我正在使用 FileSystemObject 列出文件,但似乎无法获取图标...

我在 VBS 中找到了一个脚本,可以将文件的图标保存到 .ico 中.
它读取文件(PE资源文件、.exe或dll)并解析图标数据。 我修改了该脚本以返回图标的字节,将其转换为 Base64 并在 HTML 中使用嵌入 Base64 图像。 这是原始脚本: http://gilpin.us/IconSiphon/

问题

  1. )在大多数情况下如果 .ico 包含多个图标(多种尺寸和颜色深度),但我无法指定使用哪一个(因为我需要 16x16 图标)。

  2. ) 并非所有图标都显示

  3. ) 由于读取 exe 和 dll,许多文件可能会很慢(但我对此没意见,我可以缓存已获取的图标)

我也尝试过一些 ActiveX 控件,但似乎都无法正常工作。即使是微软提供的(ShellFolderView 或 ListView)也有很多错误。

要求

  • 必须显示 16x16 图标

  • 必须允许多个文件选择

  • 所有内容都必须嵌入 hta (如果可能的话)。没有外部 .exe

有谁知道实现这一目标的方法吗?

谢谢!

I'm building an HTA application in which I need to display a list of file with their associated system icon.
I'm using FileSystemObject to list the file but there seem to have no way to get the icon...

I've found a script in VBS that can save the icon of a file into a .ico .
It read the file (PE resource file, .exe or dll) and parse the icon data.
I modified that script to return the icon's bytes, convert it to base64 and use embed base64 images in HTML.
Here's the original script: http://gilpin.us/IconSiphon/

Issue

  1. ) In most case the .ico contains multiple icons (many sizes and color depth) but there's no way I can specify which one to use (as I need 16x16 icons).

  2. ) Not all icons are displayed

  3. ) Could be slow with many file as it read exe and dll (but I'm ok with that, I can cache already fetched icon)

I've also tried some ActiveX control but none seem to work properly. Even those provided by microsoft (ShellFolderView or ListView) are very buggy.

Requirements

  • Must display 16x16 icon

  • Must allow multiple file selection

  • Everything must be embed in hta (if possible). No external .exe

Does anyone know a way to achieve that?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

三生殊途 2024-12-08 15:06:01

文件系统对象将为您提供枚举本地文件系统上的文件所需的函数。然而,要获取图标图像,您需要根据 @seachase 的响应使用 win32 api 或外部 exe。

但是,您可以使用 wshApiToolkit activex 对象通过 hta 中的 javascript 访问 win32api - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex= &startPage=1

找到它的副本,您就快完成了。它确实需要使用您的代码和 shell 来分发 activex 对象,并从 HTA 内执行注册过程,因此这可能会违反您的第三个约束。尽管我相信您可以将 exe 以 Base64 编码到 dataurl 中的 hta 中,并将其写回文件系统,这样它至少会被捆绑到一个文件中。如果您支持该选项,那么嵌入一个执行相同操作的 exe 可能会满足您的要求。

绝对是一些 hacky 的东西在未来的操作系统版本上可能不稳定 - 哎呀我什至不确定 wshApiToolkit 是否可以在 Windows 7 上工作,而 8 即将到来。祝你好运!

The filesystemobject will provide you the necessary functions for enumerating files on the local filesystem. However to get the icon image you will need to use the win32 api per @seanchase's response or an external exe.

However you can access the win32api via javascript in the hta using the wshApiToolkit activex object - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1

Find a copy of that and you're close to being done. It does require distributing the activex object with your code and shell executing the registration process from within the HTA so that might violate your third constraint. Though I believe you can base64 encode the exe into the hta in a dataurl and write that back out to the file system so it would at least be bundled into a single file. If you support that option then maybe embedding an exe that does the same would meet your requriements.

Definitely some hacky stuff that may be unstable on future OS versions - heck I'm not even sure the wshApiToolkit works on windows 7, and 8 is just around the corner. Good luck!

做个少女永远怀春 2024-12-08 15:06:01

您表示您愿意安装 ActiveX 组件并在 HTA 中使用它们。

如果我有时间,我会通过使用 Visual Studio 创建 ActiveX 组件来调用 FindResourceLoadResourceLockResource 来自己解决此问题。这些将允许访问组图标资源,然后我将为其提供丰富的接口来迭代图标,从而提供提取 BMP(或 PNG)的能力。

这就是我“如何”去实现这一目标,而不是实际去做。

You indicated you're opened to installing ActiveX components and using them in your HTA.

If I had the time, I would approach this for myself by creating ActiveX components using Visual Studio to call FindResource, LoadResource and LockResource. These will enable access to the Group Icon resource for which I would then provide rich interfaces to iterate through the Icons offering the ability to extract BMPs (or PNGs).

This is "how" I would go about achieving this short of actually going off doing it.

分开我的手 2024-12-08 15:06:01

一旦我构建了一个类似的 HTA 界面,我就遇到了同样的问题。我通过创建自定义图标库并使用 base64 转换图像解决了该问题。您可以通过转换或使用精灵来实现相同的目的。许多 UI 都这样做,甚至 java.swing 也有自己的集合嵌入。正如您所注意到的,读取 *.dll 会降低应用程序的速度

Once I build a similar HTA interface and I faced the same problem. I solved the problem by creating a custom icon gallery and converting the images using base64. You may achieve the same by either converting or using sprite. Many UI does it, even java.swing has its own collection embbebed. As you noticed, reading from *.dll can speed down the application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文