Vista如何为与我的应用程序关联的文档生成图标? [英] How does Vista generate the icon for documents associated to my application?

查看:130
本文介绍了Vista如何为与我的应用程序关联的文档生成图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以影响这个过程吗?

我有一个用.NET 3.5 / VS2008构建的应用程序。我使用win32 .res文件在应用程序中嵌入了多个图标。这是在VS2008中的项目的属性框中完成的 - 而不是指定.ico文件,勾选框以指定.res文件。在.res文件中,您可以拥有多个图标。请参阅此处

Can I affect the process?
I have an application built in .NET 3.5 / VS2008. I have embedded multiple icons into the app with a win32 .res file. This is done in the Properties box for the Project in VS2008 - instead of specifying an .ico file, tick the box to specify a .res file. In the .res file you can have multiple icons. See here for what I mean.

每个图标包括256x256xRGB(PNG Cmopressed)Vista等级图像,256x256x32bit图像,以及通常的48x48,32x32和16x16图像级联,采用各种颜色组合。
如果我在资源管理器中查看生成的exe文件,我会看到美丽的256x256 Vista图像。

Each icon includes a 256x256xRGB (PNG Cmopressed) "Vista grade" image, a 256x256x32bit image, and the usual cascade of 48x48, 32x32, and 16x16 images in various color combos. If I view the resulting exe in Explorer, I see the big beautiful 256x256 Vista images.

然后,我可以使用右键单击>打开方式...>在Vista的资源管理器中设置默认程序点击流,将文件扩展名关联到我的应用程序。但是,文档旁边显示的图标是应用程序图标的小版本,覆盖在看起来像带有折角的白纸的顶部。

I can then associate a file extension to my app, using the right click > "Open With..." > Set Default Program clickstream in Vista's Explorer. But the icon displayed next to the document is then a small version of the app icon, overlayed on top of what looks like a white sheet of paper with a folded corner.

结果是当原始图像以小图标版本显示时,可以看到小图像可见。它看起来很糟糕。

The result is that the original image is waaaay to small to be visible, when it is shown in "small icon" version. It looks terrible.

我知道可以完全省略折叠的纸张,或者至少可以覆盖更大的图像。例如,C#文件的图标有一张折叠的纸张,但C#标志很大且可见。我怎么能得到这个?安装WinZip 12时.zip文件的图标很大且可见,并且没有折叠的纸张。

I know it is possible to completely omit the folded piece of paper, or at least to get a much larger image overlayed on it. The icon for a C# file, for example, has a folded sheet of paper, but the C# emblem is large and visible. How can I get this? The icon for .zip files when WinZip 12 is installed, is large and visible, and has no folded sheet of paper.

文档图标是否与文件不同图标换的应用程序?为了注册Vista将用于与我的应用程序关联的文档的图标,我的应用程序中是否有必要执行的操作?

Is the icon-for-documents different than the icon-for-the-application? Is there something in my app that I have to do in order to register an Icon that Vista will use for documents associated to my app?

推荐答案

注册表中列出了文件扩展名的图标和文件关联。更具体地说, HKEY_CLASSES_ROOT\.ext 条目包含内容类型,感知类型,并且在(默认)值中是实际的关联。例如,.cs文件的默认值为 VisualStudio.cs.9.0 (我有VS 2008)。您可以查看 HKEY_CLASSES_ROOT \VisualStudio.cs.9.0 ,以查看与此文件类型相关的实际图标,程序和命令。特别是, HKEY_CLASSES_ROOT \VisualStudio.cs.9.0\DefaultIcon 是告诉资源管理器为这种类型的文件显示哪个图标的条目。它指向该二进制文件中的二进制文件和资源ID。

The icons and file associations for file extensions are listed in the registry. More specifically, HKEY_CLASSES_ROOT\.ext entries contain the content type, perceived type and in the (Default) value is the actual association. For example, .cs files have default value of VisualStudio.cs.9.0 (I've got VS 2008). You can check the HKEY_CLASSES_ROOT\VisualStudio.cs.9.0 to see the actual icon, program and commands associated with this file type. In particular, the HKEY_CLASSES_ROOT\VisualStudio.cs.9.0\DefaultIcon is the entry that tells Explorer which icon to show for files of this type. It points to a binary and a resource ID in that binary.

通过右键单击 - >打开方式...将文件类型与程序关联时,不要指定默认图标,因此资源管理器会获取您应用的图标并将其覆盖在通用文档图标上。

When you associate a file type with a program through the right click -> Open With..., you don't specify a default icon, so Explorer takes the icon of your app and overlays it over a generic document icon.

正确的方法是将其包含在内您设置相应的注册表项以将文件类型与您的应用程序和图标相关联。您需要包含的确切注册表值取决于您要添加到该文件类型的上下文菜单中的命令,但至少您需要Open命令。对于.cs文件,您可以看到 HKEY_CLASSES_ROOT \VisualStudio.cs.9.0 \ Shell_\\Commands\Open 条目(默认)包含要在调用Open命令时启动的应用程序的值。 (您现在可以忽略 ddeexec 部分)

The right approach would be to include as part of your setup the appropriate registry entries to associate the file type with your application and your icon. The exact registry values you need to include depend on the commands you want added to the context menu for that file type, but at the very least you want the Open command. In the case of .cs files, you can see that there is an entry HKEY_CLASSES_ROOT\VisualStudio.cs.9.0\Shell\Commands\Open with (Default) value containing the application to start when the Open command is invoked. (You can ignore the ddeexec part for now)

请记住 HKEY_CLASSES_ROOT 是两个注册表分支的映射视图: HKEY_CURRENT_USER \Software\Classes HKEY_LOCAL_MACHINE \Software \Classes 。如果您希望文件关联适用于所有用户,则需要写入 HKEY_LOCAL_MACHINE 。您的设置需要以管理员身份运行才能执行此操作。否则,尝试写入 HKEY_CLASSES_ROOT 将失败并拒绝访问或写入 HKEY_CURRENT_USER 并仅为此进行关联当前用户。 (这两者中的哪一个确实会发生取决于几个方面,比如操作系统是什么,用户是管理员还是不提升等等)

Keep in mind that the HKEY_CLASSES_ROOT is a mapped view of two registry branches: HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes. If you want your file association to be for all users, you need to write to HKEY_LOCAL_MACHINE. Your setup needs to run as admin to do that. Otherwise, attempting to write to HKEY_CLASSES_ROOT will either fail with access denied or write to HKEY_CURRENT_USER and do the association only for the current user. (Which of the two exactly will happen depends on several things, like what the OS is, whether the user is admin but not elevated and so on)

你可以阅读所有这一切都在自定义文件类型(文件关联) MSDN上的部分。特别是文件类型使用客户端程序注册程序将为您提供完整的基础知识这样做。

You can read about all this in Customizing File Types (Files Associations) section on MSDN. In particular, File Types and Registering Programs with Client Programs would give you the basics of how exactly to do this.

这篇关于Vista如何为与我的应用程序关联的文档生成图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆