Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM
创建图标标记 Handlers
Creating Icon Overlay Handlers
图标标记是放在代表着某个 Shell 对象的图标之左下角的小图像。它们通常被加在一个对象的图标的身上来提供一些额外信息。例如,有个常见的图标标记是用来表示图标对应着一个链接而非真正的文件或文件夹的小箭头。除了系统提供的标准图标标记,用户还可以通过实现和注册一个图标标记 handler 来给特殊的 Shell 对象自定义图标标记。
Icon overlays are small images placed at the lower-left corner of the icon that represents a Shell object. They are normally added to an object's icon to provide some extra information. For instance, a commonly used icon overlay is the small arrow that indicates that the icon represents a link, rather than the actual file or folder. In addition to the standard icon overlays that are provided by the system, you can request custom icon overlays for specified Shell objects by implementing and registering an icon overlay handler.
注意 系统能支持的不同图标标记数量受到系统图像列表中图标标记可用空间的限制。目前为图标标记分配了15个插槽,其中一些被系统所保留。因此,图标标记 handlers 应该只在现有选择无法令人满意的情况下采用。
Note The number of different icon overlay handlers that the system can support is limited by the amount of space available for icon overlays in the system image list. There are currently fifteen slots allotted for icon overlays, some of which are reserved by the system. For this reason, icon overlay handlers should be implemented only if there are no satisfactory alternatives.
Creating Shell Extension Handlers 里讨论了实现和注册一个 Shell 拓展 handler 的普遍过程。这篇文档重点在于实现图标标记 handler 的方面。
The general procedures for implementing and registering a Shell extension handler are discussed in Creating Shell Extension Handlers. This document focuses on those aspects of implementation that are specific to icon overlay handlers.
- 图标标记如何工作
- 注册图标标记 handler
- 实现图标标记 handler
- 实现 GetOverlayInfo
- 实现 GetPriority
- 实现 IsMemberOf
- How Icon Overlay Handlers Work
- Registering Icon Overlay Handlers
- Implementing Icon Overlay Handlers
- Implementing GetOverlayInfo
- Implementing GetPriority
- Implementing IsMemberOf
图标标记如何工作
How Icon Overlay Handlers Work
图标标记 handler 是与特定图标标记相关联的组件对象模型(COM)对象。 Shell 和 handler 之间的通信都通过 handler 的 IShellIconOverlayIdentifier 接口。
Icon overlay handlers are Component Object Model (COM) objects that are associated with a particular icon overlay. All communication between the Shell and the handler takes place through the handler's IShellIconOverlayIdentifier interface.
当 Shell 启动时,所有的图标标记都会被 Shell 通过调用它们的以下两个 IShellIconOverlayIdentifier 方法来完成初始化:
When the Shell starts up, it initializes all icon overlay handlers by calling two of their IShellIconOverlayIdentifier methods:
- Shell 调用 IShellIconOverlayIdentifier::GetOverlayInfo 来获得 handler 的图标标记的位置。图标标记 handler 返回包含标记图像的文件的文件名以及它在文件中的索引。然后 Shell 将图标标记加入到系统图像列表中。
- The Shell calls IShellIconOverlayIdentifier::GetOverlayInfo to request the location of the handler's icon overlay. The icon overlay handler returns the name of the file containing the overlay image, and its index within that file. The Shell then adds the icon overlay to the system image list.
- Shell 调用 IShellIconOverlayIdentifier::GetPriority 来确定图标标记的优先级。优先级值是从0到100的数字,100代表着最低优先级。如果为特定文件请求的图标标记超过一个,Shell 将根据这个值来帮助它决定显示哪个图标标记。
- The Shell calls IShellIconOverlayIdentifier::GetPriority to determine the icon overlay's priority. The priority value is a number from zero to 100, with 100 indicating the lowest priority. If more than one icon overlay is requested for a particular file, the Shell uses this value to help it determine which icon overlay to display.
在绘制一个对象的图标之前,Shell 将对象的名字传递给每个图标标记 handler 的 IShellIconOverlayIdentifier::IsMemberOf 方法。一个图标标记 handler 通常与特定的一组文件相关联。例如,图标标记 handler 可能会为某一文件类型的所有成员请求一个标记,比如文件拓展名为 .myp 的所有文件。如果一个 handler 想要让它的图标标记显示出来,他将返回 S_OK。然后 Shell 调用 handler 的 IShellIconOverlayIdentifier::GetOverlayInfo 方法来确定显示哪个图标。
Before painting an object's icon, the Shell passes the object's name to each icon overlay handler's IShellIconOverlayIdentifier::IsMemberOf method. An icon overlay handler is normally associated with a particular group of files. For example, the icon overlay handler might request an overlay for all members of a file type, such as all files with an .myp file name extension. If a handler wants to have its icon overlay displayed, it returns S_OK. The Shell then calls the handler's IShellIconOverlayIdentifier::GetOverlayInfo method to determine which icon to display.
注意 图像一旦在初始化期间被载入系统图像列表,就不能被改变了。在初始化后,文件名和索引仅用来识别图标标记。系统不会载入新的图标标记。当 IShellIconOverlayIdentifier::GetOverlayInfo 被第一次调用时,你的 handler 必须返回和之前一样的文件名和索引。
Note Once the image has been loaded into the system image list during initialization, it cannot be changed. After initialization, the file name and index are used only to identify the icon overlay. The system will not load a new icon overlay. When IShellIconOverlayIdentifier::GetOverlayInfo is called, your handler must return the same file name and index that was specified when the function was first called.
尽管只能显示一个图标标记,但是一个对象可能会有来自超过一个 handler 的图标标记请求。在这种情况下 Shell 通过显示最高优先级的图标标记来解决冲突。Shell 通过一系列内置的规则解决了许多类似的冲突。如果这些规则不够充分,Shell 会在初始化期间比较 handler 的 IShellIconOverlayIdentifier::GetPriority 方法指定的优先级值。
Although only one icon overlay can be displayed, it is possible for an object to have icon overlays requested by more than one handler. In that case, the Shell resolves the conflict by displaying the highest priority icon overlay. The Shell resolves many such conflicts with an internal set of rules. If these rules are not sufficient, the Shell compares the priority values that were specified by the handlers' IShellIconOverlayIdentifier::GetPriority method during initialization.
注册图标标记 Handler
Registering Icon Overlay Handlers
除了普通的 COM 注册,你还必须为该 handler 在这个键下创建一个子键。
In addition to normal COM registration, you must also create a subkey named for the handler under this key.
HKEY_LOCAL_MACHINE
Software
Microsoft
Windows
CurrentVersion
Explorer
ShellIconOverlayIdentifiers
将子键的默认值设置为该对象的类标识符(CLSID)GUID 的字符串形式。下面的例子展示了如何注册一个命名为 MyOverlay 的图标标记 handler。
Set the default value of the subkey to the string form of the object's class identifier (CLSID) GUID. The following example illustrates how to register an icon overlay handler named MyOverlay.
HKEY_LOCAL_MACHINE
Software
Microsoft
Windows
CurrentVersion
Explorer
ShellIconOverlayIdentifiers
MyOverlay
(Default) = {MyOverlay CLSID GUID}
MyOverlay.rgs:
HKCR
{
NoRemove CLSID
{
ForceRemove {CB36C229-73C6-442E-926B-78FB1E8DB581} = s 'MyOverlay Class'
{
ForceRemove Programmable
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{914BCF58-3175-46D5-BE46-702284548A17}'
Version = s '1.0'
}
}
} HKLM
{
NoRemove SOFTWARE
{
NoRemove Microsoft
{
NoRemove Windows
{
NoRemove CurrentVersion
{
NoRemove Explorer
{
NoRemove ShellIconOverlayIdentifiers
{
ForceRemove 'MyOverlay' = s '{CB36C229-73C6-442E-926B-78FB1E8DB581}'
{
}
}
}
}
}
}
}
}
实现图标标记 Handler
Implementing Icon Overlay Handlers
图标标记 handler 是进程内 COM 对象,作为 DLL 来实现。它除了 IUnknown 外还输出一个接口:IShellIconOverlayIdentifier。这个接口有三个方法:IShellIconOverlayIdentifier::GetOverlayInfo、IShellIconOverlayIdentifier::GetPriority和IShellIconOverlayIdentifier::IsMemberOf。
Icon overlay handlers are in-process COM objects, implemented as DLLs. They export one interface in addition to IUnknown: IShellIconOverlayIdentifier. This interface has three methods: IShellIconOverlayIdentifier::GetOverlayInfo, IShellIconOverlayIdentifier::GetPriority, and IShellIconOverlayIdentifier::IsMemberOf.
实现 GetOverlayInfo
Implementing GetOverlayInfo
这个方法在初始化期间被第一次调用。该方法会返回包含了图标标记图像的文件的完全有效的路径,以及文件中基于0的索引。然后 Shell 将图像加入到系统图像列表中。图标标记可以被任何标准文件类型的文件所包含,包括 .exe、.dll、.ico。
This method is first called during initialization. The method returns the fully qualified path of the file containing the icon overlay image, and its zero-based index within the file. The Shell then adds the image to the system image list. Icon overlays can be contained in any of the standard file types, including .exe, .dll, and .ico.
在初始化完成后,当 Shell 需要显示handler的图标标记时,将会调用 IShellIconOverlayIdentifier::GetOverlayInfo。该方法应该返回与初始化期间一样的文件名和索引。尽管 Shell 是使用系统图像列表中缓存的图像而不是从文件中载入,图标标记仍然由它的文件名和索引来标识。
After initialization is complete, the Shell calls IShellIconOverlayIdentifier::GetOverlayInfo when it needs to display the handler's icon overlay. The method should return the same file name and index that it did during initialization. Although the Shell uses the image that is cached in the system image list rather than loading the image from the file, an icon overlay is still identified by its file name and index.
实现 GetPriority
Implementing GetPriority
该方法仅在初始化期间被调用。它为handler的图标标记赋予优先级值。该值的范围是从0到100,其中100是最低优先级。这个优先级值的目的在于帮助 Shell 解决当多个图标标记指定到一个对象时产生的冲突。 Shell 一开始使用一系列规则来确定最高优先级的图标标记。如果这些规则不能解决冲突,那么 IShellIconOverlayIdentifier::GetPriority 分配给图标标记的值将决定优先级。
This method is called only during initialization. It assigns a priority value to the handler's icon overlay. The value can range from zero to 100, where 100 is the lowest priority. The purpose of this priority value is to help the Shell resolve the conflict that arises when multiple icon overlays are specified for a single object. The Shell first uses an internal set of rules to determine the highest priority icon overlay. If these rules do not resolve the conflict, the values assigned to the icon overlays by IShellIconOverlayIdentifier::GetPriority determine priority.
IShellIconOverlayIdentifier::GetPriority 设置的优先级值并不是一个可靠的方式来解决两个不相关的图标标记之间的冲突。你的 handler 无法确定其他 handler 在使用什么优先级值。通常情况下,你应该将值设为0。然而,当你为同一个对象实现了两个或更多图标标记 handler 时,优先级值是十分有用的。通过适当地设置优先级值,你可以指定哪个被请求的图标标记将被显示。
The priority value set by IShellIconOverlayIdentifier::GetPriority is not a reliable way to resolve conflicts between unrelated icon overlay handlers. There is no way for your handler to determine what priority values other handlers are using. Normally, you should set the value to zero. However, the priority value is useful when you have implemented two or more icon overlay handlers that can request icon overlay icons for the same object. By setting the priority values appropriately, you can specify which of the requested icon overlays will be displayed.
实现 IsMemberOf
Implementing IsMemberOf
Shell 调用该方法来确定是否应该为一个特定对象显示一个 handler 的图标标记。它通过传递它的名字给该方法来指定对象。如果一个 handler 希望它的图标标记被显示,IShellIconOverlayIdentifier::IsMemberOf 返回 S_OK。如果不,返回S_FALSE。
The Shell calls this method to determine whether it should display a handler's icon overlay for a particular object. It specifies the object by passing its name to the method. If a handler wants to have its icon overlay displayed, IShellIconOverlayIdentifier::IsMemberOf returns S_OK. If not, it returns S_FALSE.
图标标记 handler 通常试图与特定的一组文件一起工作。一个典型的例子就是由特定的文件拓展名标识的文件类型。一个图标标记 handler 可以为该文件类型的所有文件请求一个图标标记。有些 handler 仅当该类型的一个文件处于某种特定状态时请求一个图标标记。然而,图标标记 handler 可以自由地为任意它们想要的对象请求图标标记。
Icon overlay handlers are normally intended to work with a particular group of files. A typical example is a file type, identified by a specific file name extension. An icon overlay handler can request an icon overlay for all files of the file type. Some handlers request an icon overlay only if a file of the file type is in a particular state. However, icon overlay handlers are free to request their icon overlay for any object that they want.
Send comments about this topic to Microsoft
Build date: 4/28/2010
—————————————————————————————————————
本文翻译自MSDN,图片及代码为本人原创,如需转载请注明出处。
http://www.cnblogs.com/lantingji/p/5849860.html
Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM的更多相关文章
- Creating Icon Overlay Handlers / 创建图标标记 Handlers (续) / VC++, Windows, DLL, ATL, COM
创建图标标记 Handlers (续) 1.新建一个ATL Project. 2.建议将 Project Property 中 Linker – General - “Register Output” ...
- Creating Context Menu / 创建上下文菜单项 / VC++, Windows, DLL, ATL, COM
创建上下文菜单项 1.新建一个ATL Project. 2.建议将Project Property中Linker – General - “Register Output” 设为no,C/C++ - ...
- Electron为文件浏览器创建图标(三)
在前面的文章中,请看之前文章,我们已经完成了使用 electron做文件浏览器这么一个应用,现在我们需要为应用创建图标操作.为应用创建图标以后,我们就可以从计算机中与其他应用区分开来,如果我们自己会做 ...
- Ubuntu创建图标
起因 安装一些软件时,总是没有图标,导致无法固定到docky栏,所以极为不方便,所以需要自己创建图标. 操作 以创建微信图标为例 [Desktop Entry] Name=Wecaht #名字 Com ...
- javascript学习笔记(四):事件处理函数和动态创建html标记。
1 HTML的事件属性 全局事件属性:HTML 4 增加了使事件在浏览器中触发动作的能力,比如当用户点击元素时启动 JavaScript. a. Window 事件属性,针对 window 对象触发 ...
- [Android]使用Dagger 2依赖注入 - 图表创建的性能(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5098943.html 使用Dagger 2依赖注入 - 图表创 ...
- Creating Dialogbased Windows Application (3) / 创建基于对话框的Windows应用程序(三)Checkbox的应用、窗体置顶、设置图标 / VC++, Windows
创建基于对话框的Windows应用程序(三) —— Checkbox的应用.窗体置顶.设置图标 上一节创建的窗体应用程序中,我们用到了Button和StaticText这两个控件.这一节中我们将学习使 ...
- javascript 百度地图无秘钥(appkey)创建marker标记地图
创建简单的marker地图不一定需要去百度地图申请key,简单代码实现marker地图,效果如图: html代码如下,代码中的baidu.api.js参考后面的隐藏代码: <!DOCTYPE h ...
- ubuntu下载安装软件并创建图标
本列以安装webstorm软件 1.官网下载软件的压缩包 2.解压 umlinux@umlinux-PC:~/idea$ tar -zxvf ideaIU-2020.3.1.tar.gz 3.找到we ...
随机推荐
- (转) 在Eclipse中进行C/C++开发的配置方法(20140721最新版)
本文转载自:http://blog.csdn.net/baimafujinji/article/details/38026421 Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其 ...
- bzoj3743 Kamp
Description 一颗树n个点,n-1条边,经过每条边都要花费一定的时间,任意两个点都是联通的. 有K个人(分布在K个不同的点)要集中到一个点举行聚会. 聚会结束后需要一辆车从举行聚会的这点出发 ...
- NAND flash和NOR flash的区别详解
我们使用的智能手机除了有一个可用的空间(如苹果8G.16G等),还有一个RAM容量,很多人都不是很清楚,为什么需要二个这样的芯片做存储呢,这就是我们下面要讲到的.这二种存储设备我们都统称为“FLASH ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- 使用 Override 和 New 关键字进行版本控制
使用 Override 和 New 关键字进行版本控制 C# 语言经过专门设计,以便不同库中的基类与派生类之间的版本控制可以不断向前发展,同时保持向后兼容. 这具有多方面的意义.例如,这意味着在基类中 ...
- PLSQL_性能优化系列09_Oracle Partition Table数据分区表
2014-08-22 Created By BaoXinjian
- PLSQL_长脚本如何判断需耗时多久v.sql / v.sqltext / v.sqlarea / v.sql_plan及nohup(案例)
2014-08-27 Created By BaoXinjian
- Tornado (and Twisted) in the age of asyncio》
Tornado (and Twisted) in the age of asyncio>
- 跨浏览器复制神器 ZeroClipboard 2.x快速入门详解
有些时候,我们希望让用户在网页上完成某个操作就能自动将指定的内容复制到用户计算机的剪贴板中.但是出于安全原因,大多数现代浏览器都未提供通用的剪贴板复制接口(或即便有,也默认被禁用).只有IE浏览器可以 ...
- linux ps命令(转载)
来源:http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html Linux中的ps命令是Process Status的缩写.ps命令用来 ...