始建Logo标志 Handlers
(续)

成立Logo标志 Handlers

创立上下文菜单项 

 

Creating Icon Overlay Handlers

 

1、新建二个ATL Project。

 

1、新建叁个ATL Project。

图片 1

Logo标识是坐落代表着某些 Shell
对象的图标之左下角的小图像。它们平时被加在三个对象的图标的身上来提供一些额外新闻。比方,有个布满的Logo标志是用来表示Logo对应着贰个链接而非真正的文本或文件夹的小箭头。除了系统提供的业内Logo标识,顾客还足以经过落到实处和挂号多少个Logo标记handler 来给特殊的 Shell 对象自定义Logo标识。

图片 2

2、建议将 Project Property 中 Linker –
General – “Register Output” 设为 no,C/C++ – “Code Generation” –
“Runtime Library” 设为 /MTd。

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.

2、建议将Project Property中Linker – General – “Register Output”
设为no,C/C++ – “Code Generation” – “Runtime Library” 设为 /MTd。

图片 3

图片 4

 图片 5

图片 6

注意
 
系统能支撑的不等Logo标识数量受到系统图像列表中Logo标识可用空间的限量。最近为Logo标志分配了十七个插槽,此中一些被系统所保存。由此,图标标识handlers 应该只在现存选用不可能令人满意的场所下利用。

图片 7

3、在 Solution Explorer 中右键 Add
Class,选用 ATL Simple Object。并在弹出的对话框中为该 Class
命名。

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.

3、在Solution Explorer中右键Add Class,选用ATL Simple
Object。并在弹出的对话框中为该Class命名。

图片 8

 

 图片 9

图片 10

Creating Shell Extension Handlers 里探讨了落成和注册三个 Shell 扩充handler 的大范围经过。那篇文书档案重视在于得以实现Logo标志 handler 的地点。

图片 11

4、增添完毕后提出 Build 一下
Project,MIDL compiler 将基于 .idl 文件生成 IIDs and CLSIDs。

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.

4、增多完结后提议Build一下Project,MIDL compiler将依照 .idl文件生成IIDs
and CLSIDs。

图片 12

 

 图片 13

5、切换来新添 Class 的 .h
文件中,使其后续接口 IShellIconOverlayIdentifier。

图标标识怎么做事

5、(可选卡塔尔国在Solution Explorer中右键Add Resource导入图标财富。

图片 14

挂号Logo标志 handler

 图片 15

图片 16

福寿齐天图标标志 handler

6、切换来新扩张Class的
.h文件中,使其持续接口IShellExtInit和IContextMenu。并在
.cpp文件中,参照MSDN给出达成。

图片 17

  • 实现 GetOverlayInfo
  • 实现 GetPriority
  • 实现 IsMemberOf

 图片 18

图片 19

How Icon Overlay Handlers Work

图片 20

图片 21图片 22

Registering Icon Overlay Handlers

图片 23

 1 // MyOverlay.h : Declaration of the CMyOverlay
 2 
 3 #pragma once
 4 #include "resource.h"       // main symbols
 5 
 6 
 7 
 8 #include "Example_i.h"
 9 #include <ShlObj.h>
10 
11 
12 
13 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
14 #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
15 #endif
16 
17 using namespace ATL;
18 
19 
20 // CMyOverlay
21 
22 class ATL_NO_VTABLE CMyOverlay :
23     public CComObjectRootEx<CComSingleThreadModel>,
24     public CComCoClass<CMyOverlay, &CLSID_MyOverlay>,
25     public IDispatchImpl<IMyOverlay, &IID_IMyOverlay, &LIBID_ExampleLib, 
26     /*wMajor =*/ 1, /*wMinor =*/ 0>,
27     public IShellIconOverlayIdentifier
28 {
29 public:
30     CMyOverlay()
31     {
32     }
33 
34 DECLARE_REGISTRY_RESOURCEID(IDR_MYOVERLAY)
35 
36 
37 BEGIN_COM_MAP(CMyOverlay)
38     COM_INTERFACE_ENTRY(IMyOverlay)
39     COM_INTERFACE_ENTRY(IDispatch)
40     COM_INTERFACE_ENTRY(IShellIconOverlayIdentifier)
41 END_COM_MAP()
42 
43 
44 
45     DECLARE_PROTECT_FINAL_CONSTRUCT()
46 
47 
48     HRESULT FinalConstruct()
49     {
50         return S_OK;
51     }
52 
53     void FinalRelease()
54     {
55     }
56 
57 public:
58     STDMETHOD(IsMemberOf)(THIS_ _In_ PCWSTR pwszPath, DWORD dwAttrib);
59     STDMETHOD(GetOverlayInfo)(THIS_ _Out_writes_(cchMax) PWSTR pwszIconFile,
60         int cchMax, _Out_ int * pIndex, _Out_ DWORD * pdwFlags);
61     STDMETHOD(GetPriority)(THIS_ _Out_ int * pIPriority);
62 
63 };
64 
65 OBJECT_ENTRY_AUTO(__uuidof(MyOverlay), CMyOverlay)

Implementing Icon Overlay Handlers

图片 24

MyOverlay.h

  • Implementing GetOverlayInfo
  • Implementing GetPriority
  • Implementing IsMemberOf

图片 25图片 26

6、根据 MSDN 实现该 Class。

 

 1 // MyContextMenu.h : Declaration of the CMyContextMenu
 2 
 3 #pragma once
 4 #include "resource.h"       // main symbols
 5 
 6 
 7 
 8 #include "ContextMenuExample_i.h"
 9 #include <Shlobj.h>
10 
11 
12 
13 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
14 #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
15 #endif
16 
17 using namespace ATL;
18 
19 
20 // CMyContextMenu
21 
22 class ATL_NO_VTABLE CMyContextMenu :
23     public CComObjectRootEx<CComSingleThreadModel>,
24     public CComCoClass<CMyContextMenu, &CLSID_MyContextMenu>,
25     public IDispatchImpl<IMyContextMenu, &IID_IMyContextMenu, 
26     &LIBID_ContextMenuExampleLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
27     public IShellExtInit,
28     public IContextMenu
29 {
30 public:
31     CMyContextMenu()
32     {
33     }
34 
35 DECLARE_REGISTRY_RESOURCEID(IDR_MYCONTEXTMENU)
36 
37 
38 BEGIN_COM_MAP(CMyContextMenu)
39     COM_INTERFACE_ENTRY(IMyContextMenu)
40     COM_INTERFACE_ENTRY(IDispatch)
41     COM_INTERFACE_ENTRY(IShellExtInit)
42     COM_INTERFACE_ENTRY(IContextMenu)
43 END_COM_MAP()
44 
45 
46 
47     DECLARE_PROTECT_FINAL_CONSTRUCT()
48 
49     HRESULT FinalConstruct();
50 
51     void FinalRelease();
52 
53 public:
54     // IShellExtInit Method
55     HRESULT STDMETHODCALLTYPE Initialize(
56         _In_opt_  PCIDLIST_ABSOLUTE pidlFolder,
57         _In_opt_  IDataObject *pdtobj,
58         _In_opt_  HKEY hkeyProgID);
59 
60     // IContextMenu Method
61     HRESULT STDMETHODCALLTYPE QueryContextMenu(
62         _In_  HMENU hmenu,    
63         _In_  UINT indexMenu,    
64         _In_  UINT idCmdFirst,
65         _In_  UINT idCmdLast,
66         _In_  UINT uFlags);
67 
68     HRESULT STDMETHODCALLTYPE InvokeCommand(
69         _In_  CMINVOKECOMMANDINFO *pici);
70 
71     HRESULT STDMETHODCALLTYPE GetCommandString(
72         _In_  UINT_PTR idCmd,
73         _In_  UINT uType,
74         _Reserved_  UINT *pReserved,
75         _Out_writes_bytes_((uType & GCS_UNICODE) ? (cchMax * sizeof(wchar_t)) : cchMax) _When_(!(uType & (GCS_VALIDATEA | GCS_VALIDATEW)), _Null_terminated_)  CHAR *pszName,
76         _In_  UINT cchMax);
77 
78 private:
79     HBITMAP MenuIcon1;
80     HBITMAP MenuIcon2;
81     HBITMAP MenuIcon3;
82     HBITMAP MenuIcon4;
83 
84 
85 };
86 
87 OBJECT_ENTRY_AUTO(__uuidof(MyContextMenu), CMyContextMenu)

图片 27

Logo标识怎么着职业

MyContextMenu.h

图片 28

How Icon Overlay Handlers Work

  1 // MyContextMenu.cpp : Implementation of CMyContextMenu
  2 
  3 #include "stdafx.h"
  4 #include "MyContextMenu.h"
  5 
  6 
  7 // CMyContextMenu
  8 
  9 HRESULT CMyContextMenu::FinalConstruct()
 10 {
 11     HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
 12     MenuIcon1 = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
 13     MenuIcon2 = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP2));
 14     MenuIcon3 = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP3));
 15     MenuIcon4 = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP4));
 16     
 17     return S_OK;
 18 }
 19 
 20 void CMyContextMenu::FinalRelease()
 21 {
 22     if (MenuIcon1 != NULL)
 23     {
 24         DeleteObject(MenuIcon1);
 25     }
 26     if (MenuIcon2 != NULL)
 27     {
 28         DeleteObject(MenuIcon2);
 29     }
 30     if (MenuIcon3 != NULL)
 31     {
 32         DeleteObject(MenuIcon3);
 33     }
 34     if (MenuIcon4 != NULL)
 35     {
 36         DeleteObject(MenuIcon4);
 37     }
 38 }
 39 
 40 HRESULT CMyContextMenu::Initialize(
 41     _In_opt_  PCIDLIST_ABSOLUTE pidlFolder,
 42     _In_opt_  IDataObject *pdtobj,
 43     _In_opt_  HKEY hkeyProgID) {
 44     HRESULT hr;
 45     UINT    nFileCount;
 46 
 47     FORMATETC fmt =
 48     {
 49         CF_HDROP,
 50         NULL,
 51         DVASPECT_CONTENT,
 52         -1,
 53         TYMED_HGLOBAL
 54     };
 55 
 56     STGMEDIUM sm =
 57     {
 58         TYMED_HGLOBAL
 59     };
 60 
 61     hr = pdtobj->GetData(&fmt, &sm);
 62 
 63     if (FAILED(hr))
 64     {
 65         return hr;
 66     }
 67 
 68     // query quantity of selected files
 69     nFileCount = DragQueryFile((HDROP)sm.hGlobal, 0xFFFFFFFF, NULL, 0);
 70 
 71     if (nFileCount == 1) // deal with only one file
 72     {
 73         // analyze selected file
 74 
 75     }
 76     else
 77     {
 78         hr = E_INVALIDARG;
 79     }
 80 
 81     ReleaseStgMedium(&sm);
 82 
 83     return hr;
 84 }
 85 
 86 // IContextMenu Method
 87 HRESULT CMyContextMenu::QueryContextMenu(
 88     _In_  HMENU hmenu,
 89     _In_  UINT indexMenu,
 90     _In_  UINT idCmdFirst,
 91     _In_  UINT idCmdLast,
 92     _In_  UINT uFlags) {
 93 
 94     UINT uCmdID = idCmdFirst;
 95     LPCWSTR text1 = TEXT("新增层叠菜单项1");
 96     LPCWSTR text2 = TEXT("新增菜单项2");
 97     LPCWSTR text3 = TEXT("新增菜单项3");
 98     LPCWSTR text4 = TEXT("新增菜单项4");
 99     // do nothing when flag includes CMF_DEFAULTONLY.
100     if (uFlags & CMF_DEFAULTONLY)
101     {
102         return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
103     }
104     InsertMenu(hmenu, indexMenu, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);
105     indexMenu++;
106     HMENU hSubMenu = CreateMenu();
107     if (hSubMenu)
108     {
109         InsertMenu(hSubMenu, 0, MF_STRING | MF_BYPOSITION, uCmdID++, text2);
110         SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, MenuIcon2, MenuIcon2);
111         InsertMenu(hSubMenu, 1, MF_STRING | MF_BYPOSITION, uCmdID++, text3);
112         SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, MenuIcon3, MenuIcon3);
113         InsertMenu(hSubMenu, 2, MF_STRING | MF_BYPOSITION, uCmdID++, text4);
114         SetMenuItemBitmaps(hSubMenu, 2, MF_BYPOSITION, MenuIcon4, MenuIcon4);
115         // InsertMenu(hSubMenu, 3, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);//插入分隔线
116     }
117     InsertMenu(hmenu, indexMenu, MF_STRING | MF_POPUP | MF_BYPOSITION, (UINT_PTR)hSubMenu, text1);
118     SetMenuItemBitmaps(hmenu, indexMenu, MF_BYPOSITION, MenuIcon1, MenuIcon1);
119     indexMenu++;
120     InsertMenu(hmenu, indexMenu, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);
121     indexMenu++;
122 
123     // inform the explorer how many menu item we have added
124     return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, uCmdID - idCmdFirst);
125 }
126 
127 HRESULT CMyContextMenu::InvokeCommand(
128     _In_  CMINVOKECOMMANDINFO *pici) {
129     if (0 != HIWORD(pici->lpVerb))
130         return E_INVALIDARG;
131     // get index of added menu item
132     switch (LOWORD(pici->lpVerb))
133     {
134     case 0:
135     {
136         // 执行新增菜单项2触发的操作
137         STARTUPINFO si = { sizeof(si) };
138         PROCESS_INFORMATION pi;
139         TCHAR szCommandLine[] = TEXT("notepad");
140         BOOL bCreateRet = CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
141 
142         break;
143     }
144     case 1:
145     {
146         // 执行新增菜单项3触发的操作
147         STARTUPINFO si = { sizeof(si) };
148         PROCESS_INFORMATION pi;
149         TCHAR szCommandLine[] = TEXT("write");
150         BOOL bCreateRet = CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
151 
152         break;
153     }
154     case 2:
155     {
156         // 执行新增菜单项4触发的操作
157         STARTUPINFO si = { sizeof(si) };
158         PROCESS_INFORMATION pi;
159         TCHAR szCommandLine[] = TEXT("cmd");
160         BOOL bCreateRet = CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
161 
162         break;
163     }
164     default:
165     {
166         return E_INVALIDARG;
167         break;
168     }
169     }
170     return S_OK;
171 }
172 
173 HRESULT CMyContextMenu::GetCommandString(
174     _In_  UINT_PTR idCmd,
175     _In_  UINT uType,
176     _Reserved_  UINT *pReserved,
177     _Out_writes_bytes_((uType & GCS_UNICODE) ? (cchMax * sizeof(wchar_t)) : cchMax) _When_(!(uType & (GCS_VALIDATEA | GCS_VALIDATEW)), _Null_terminated_)  CHAR *pszName,
178     _In_  UINT cchMax) {
179     USES_CONVERSION;
180     LPCTSTR szPrompt;
181     // copy help info to cache when explorer ask
182     if (uType & GCS_HELPTEXT)
183     {
184         switch (idCmd)
185         {
186         case 0:
187             szPrompt = _T("新增菜单项2说明文字");
188             break;
189         case 1:
190             szPrompt = _T("新增菜单项3说明文字");
191             break;
192         case 2:
193             szPrompt = _T("新增菜单项4说明文字");
194             break;
195         default:
196             //ATLASSERT(0);           // should never get here
197             return E_INVALIDARG;
198             break;
199         }
200         if (uType & GCS_UNICODE)
201         {
202             lstrcpynW((LPWSTR)pszName, T2CW(szPrompt), cchMax);
203         }
204         else
205         {
206             lstrcpynA(pszName, T2CA(szPrompt), cchMax);
207         }
208         return S_OK;
209     }
210     return E_INVALIDARG;
211 }

图片 29

Logo标志 handler 是与一定Logo标识相关联的构件对象模型(COM)对象。 Shell 和 handler 之间的通讯都通过 handler 的 IShellIconOverlayIdentifier 接口。

7、在 .rgs文件中加多注册表音信,确认保证各GUID与 .idl文件中的黄金年代致。

图片 30

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.

 1 HKCR
 2 {
 3     NoRemove CLSID
 4     {
 5         ForceRemove {9C50C98F-E1FF-41CF-BD54-E9A3BBDDDEF8} = s 'MyContextMenu Class'
 6         {
 7             ForceRemove Programmable
 8             InprocServer32 = s '%MODULE%'
 9             {
10                 val ThreadingModel = s 'Apartment'
11             }
12             TypeLib = s '{EB1C2F43-315D-4D8F-9A2A-70E67BE888E2}'
13             Version = s '1.0'
14         }
15     }
16 
17     NoRemove *
18     {
19         NoRemove ShellEx
20         {
21             NoRemove ContextMenuHandlers
22             {
23                 ForceRemove MyContextMenu = s '{9C50C98F-E1FF-41CF-BD54-E9A3BBDDDEF8}'
24             }
25         }
26     }
27 }

图片 31图片 32

当 Shell 运维时,全数的Logo标识都会被 Shell 通过调用它们的以下八个 IShellIconOverlayIdentifier 方法来达成早先化:

8、Build Project 后展开cmd.exe,通过regsvr32发令注册或解注册生成的
.dll文件。

 1 // MyOverlay.cpp : Implementation of CMyOverlay
 2 
 3 #include "stdafx.h"
 4 #include "MyOverlay.h"
 5 #include <WinBase.h>
 6 #pragma comment(lib, "Kernel32.lib")
 7 
 8 // CMyOverlay
 9 
10 STDMETHODIMP CMyOverlay::IsMemberOf(THIS_ _In_ PCWSTR pwszPath, DWORD dwAttrib)
11 {
12     if (_tcscmp(pwszPath, L"test") == 0)
13     {
14         return S_OK;
15     }
16     else
17     {
18         return S_FALSE;
19     }
20 }
21 
22 STDMETHODIMP CMyOverlay::GetOverlayInfo(
23     THIS_ _Out_writes_(cchMax) PWSTR pwszIconFile, 
24     int cchMax, 
25     _Out_ int * pIndex,
26     _Out_ DWORD * pdwFlags)
27 {
28     
29     GetModuleFileNameW(_AtlBaseModule.GetModuleInstance(), pwszIconFile, cchMax);
30 
31     *pIndex = 0;
32 
33     *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
34 
35     return S_OK;
36 }
37 
38 STDMETHODIMP CMyOverlay::GetPriority(THIS_ _Out_ int * pIPriority)
39 {
40     *pIPriority = 0;
41 
42     return S_OK;
43 }

When the Shell starts up, it initializes all icon
overlay handlers by calling two of their IShellIconOverlayIdentifier
methods:

 图片 33

MyOverlay.cpp

  • Shell 调用 IShellIconOverlayIdentifier::GetOverlayInfo 来赢得 handler 的Logo标识的任务。Logo标识 handler 再次来到包罗标识图像的文书的文书名以致它在文件中的索引。然后 Shell 将Logo标识参与到系统图像列表中。
  • 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 来规定Logo标识的事先级。优先级值是从0到100的数字,100表示着最低优先级。借使为特定文件央求的Logo标识超过一个,Shell 将基于那几个值来增加援助它决定突显哪个Logo标识。
  • 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.

10、查看效果如下图所示。

7、在 .rgs 文件中增加注册表消息,确认保障各
GUID 与 .idl 文件中的风姿罗曼蒂克致。

在绘制一个指标的Logo从前,Shell 将目的的名字传递给各样Logo标志 handler 的 IShellIconOverlayIdentifier::IsMemberOf 格局。一个Logo标识 handler 常常与特定的生龙活虎组文件相关联。比如,Logo标识 handler 恐怕会为某一文件类型的富有成员伏乞三个标志,比如文件进行名称叫 .myp 的兼具文件。若是一个 handler 想要让它的Logo标识彰显出来,他将回来 S_OK。然后 Shell 调用 handler 的 IShellIconOverlayIdentifier::GetOverlayInfo 主意来规定展现哪个Logo。

 图片 34

 1 HKCR
 2 {
 3     NoRemove CLSID
 4     {
 5         ForceRemove {29913677-1662-46C5-8645-16F84DA6F438} = s 'MyOverlay Class'
 6         {
 7             ForceRemove Programmable
 8             InprocServer32 = s '%MODULE%'
 9             {
10                 val ThreadingModel = s 'Apartment'
11             }
12             TypeLib = s '{942F4DBB-4667-4767-A35B-52F32F623C63}'
13             Version = s '1.0'
14         }
15     }
16 }
17 
18 HKLM
19 {
20     NoRemove SOFTWARE
21     {
22         NoRemove Microsoft
23         {
24             NoRemove Windows
25             {
26                 NoRemove CurrentVersion
27                 {
28                     NoRemove Explorer
29                     {
30                         NoRemove ShellIconOverlayIdentifiers
31                         {
32                             ForceRemove '  MyOverlay' = s '{29913677-1662-46C5-8645-16F84DA6F438}'
33                             {
34                             }
35                         }
36                     }
37                 }
38             }
39         }
40     }
41 }

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.

 

8、Build Project 后透过 cmd.exe
注册或解注册生成的 .dll 文件。重启 explorer.exe 后生效。

注意
 
图像生龙活虎旦在起头化期间被载入系统图像列表,就不可能被改成了。在最先化后,文件名和目录仅用来辨别Logo标志。系统不会载入新的Logo标识。当 IShellIconOverlayIdentifier::GetOverlayInfo 被第贰回调用时,你的 handler 必须重回和在此之前同生龙活虎的公文名和目录。

——————————————————

图片 35

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.

正文为自家原创,如需转发请表明出处。

图片 36

固然只可以展现一个图标标识,不过四个目的也许会有来源抢先一个 handler 的Logo标识央求。在此种状态下 Shell 通过呈现最高优先级的Logo标志来解决冲突。Shell 通过黄金年代种类内置的规规矩矩解决了不胜枚举像样的冲突。尽管这一个准则相当不够丰富,Shell 会在最早化时期相比较 handler 的 IShellIconOverlayIdentifier::GetPriority 艺术内定的先行级值。

图片 37

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.

9、由于 slots
数量少于,检查在注册表中丰裕的子项是或不是在有效约束内(近些日子为前17个卡塔尔。按下Win+宝马X5键,通过运营对话框张开regedit.exe,按HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers的逐生龙活虎依次进行或间接Ctrl+F查找到MyOverlay项。可利用在.rgs文件中的子项名称前增添空格的主意将其地方提前。

 

图片 38

登记Logo标识 Handler

图片 39

Registering Icon Overlay Handlers

10、查看效果如下图所示。

除此之外普通的 COM 注册,你还非得为该 handler 在此个键下创设三个子键。

图片 40

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卡塔 尔(英语:State of Qatar)GUID 的字符串情势。上边的例证体现了什么注册多个命名字为 MyOverlay 的Logo标志 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

Logo标志 handler 是进度内 COM 对象,作为 DLL 来落到实处。它除了 IUnknown 外还输出二个接口:IShellIconOverlayIdentifier。这么些接口有四个格局:IShellIconOverlayIdentifier::GetOverlayInfoIShellIconOverlayIdentifier::GetPriorityIShellIconOverlayIdentifier::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

那么些方法在初叶化时期被第二回调用。该方法会重返包涵了Logo标识图像的公文的一心可行的门道,以致文件中基于0的目录。然后 Shell 将图像出席到系统图像列表中。Logo标志能够被别的标准文件类型的文件所包罗,富含 .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 是利用系统图像列表中缓存的图像并非从文件中载入,Logo标志如故由它的公文名和目录来标志。

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的Logo标识付与优先级值。该值的限定是从0到100,此中100是低于优先级。这些优先级值的意在扶持 Shell 消除当多少个Logo标志内定到叁个目标时发出的冲突。 Shell 大器晚成从头运用意气风发各个法规来规定最高优先级的Logo标识。要是那一个准绳无法淹没冲突,那么 IShellIconOverlayIdentifier::GetPriority 分配给Logo标志的值将决定优先级。

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 设置的前期级值并不是一个保障的办法来消除八个不相干的Logo标记之间的冲突。你的 handler 不大概明确其余 handler 在使用什么优先级值。平常意况下,你应当将值设为0。可是,当您为同贰个指标完毕了几个或越多Logo标识 handler 时,优先级值是不行使得的。通过适当地安装优先级值,你能够内定哪个被呼吁的Logo标识将被呈现。

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 的Logo标志。它经过传递它的名字给该格局来内定对象。若是二个 handler 希望它的Logo标志被出示,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.

Logo标志 handler 平常试图与特定的后生可畏组文件一同坐班。一个典型的例证正是由特定的文书举办名标记的文件类型。二个图标标识 handler 可感觉该文件类型的兼具文件伏乞二个Logo标志。有个别 handler 仅当该品种的两个文件处于某种特定情景时伸手二个Logo标志。然则,Logo标识 handler 能够任意地为随机它们想要的对象恳求Logo标识。

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&body=%0A%0APRIVACY%20STATEMENT%0A%0AThe%20SDK%20team%20uses%20the%20feedback%20submitted%20to%20improve%20the%20SDK%20documentation.%20We%20do%20not%20use%20your%20e-mail%20address%20for%20any%20other%20purpose.%20We%20will%20remove%20your%20e-mail%20address%20from%20our%20system%20after%20the%20issue%20you%20are%20reporting%20has%20been%20resolved.%20While%20we%20are%20working%20to%20resolve%20this%20issue,%20we%20may%20send%20you%20an%20e-mail%20message%20to%20request%20more%20information%20about%20your%20feedback.%20After%20the%20issues%20have%20been%20addressed,%20we%20may%20send%20you%20an%20e-mail%20message%20to%20let%20you%20know%20that%20your%20feedback%20has%20been%20addressed.%0A%0AFor%20more%20information%20about%20Microsoft%27s%20privacy%20policy,%20see%20.)

 

Build date: 4/28/2010

 

—————————————————————————————————————

本文翻译自MSDN,图片及代码为本人原创,如需转发请表明出处。

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图