Icon Overlay Handlers

I.Icon Overlay Handlers

I.1. Knowleged base

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.

This interface has three methods: GetOverlayInfo , GetPriority , and IsMemberOf.

  • GetOverlayInfo:

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.

  • 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.

  • IsMemberOf:

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, IsMemberOf? returns S_OK. If not, it returns S_FALSE.

I.2. Implementation

Setting up a shell extension comes down to a few steps:

– Create a class implementing the methods which the shell extension requires.

import os
from win32com.shell import shell, shellcon
import winerror

class IconOverlay:
_reg_clsid_ = '{4FC554DF-F0EE-4A4F-966C-9C49CCF14D59}'
_reg_progid_ = 'TJG.PythonPackagesOverlayHandler'
_reg_desc_ = 'Icon Overlay Handler to indicate Python packages'
_public_methods_ = ['GetOverlayInfo', 'GetPriority', 'IsMemberOf']
_com_interfaces_ = [shell.IID_IShellIconOverlayIdentifier]

def GetOverlayInfo(self):
return (r'C:\Program Files\TortoiseHg\icons\status\added.ico',
0, shellcon.ISIOI_ICONFILE)
def GetPriority(self):
return 1
def IsMemberOf(self, fname, attributes):
if os.path.exists (os.path.join (fname, "__init__.py")):
return winerror.S_OK
return winerror.E_FAIL

-Register this class as a COM Server and, probably, force explorer to restart.

win32com.server.register.UseCommandLine (IconOverlay)
keyname = r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\PyPackageOverlay'
key = win32api.RegCreateKey (win32con.HKEY_LOCAL_MACHINE, keyname)
win32api.RegSetValue (key, None, win32con.REG_SZ, IconOverlay._reg_clsid_)

II.Common questions

1) How do you actually use the IconOverlay? class ?

No, It’s a Icon overlay handler and we register it to COM server which contains the methods the shell will be calling back, so we don’t call any method after that, shell will use them.

2) I make zoom in and zoom out in Explorer, Icon overlay is not zoom follow.

This problem comes when the icon is used to make icon overlay not a multiple size icon type. Solution: create a multiple size icon. There are many software help to do it such as: FXIco

3) When changing from this icon-overlay to other icon-overlay, How to explorer know that and change the icon overlay.

We have to notify to the shell. Using SHChangeNotify function http://msdn.microsoft.com/en-us/library/windows/desktop/bb762118(v=vs.85).aspx

pidl, ignore = shell.SHILCreateFromPath(dir, 0)
shellcon.SHCNF_IDLIST | shellcon.SHCNF_FLUSH,

4) I want to create many icon overlay base on status of file.

Yes, We can do it by creating many icon overlay handers and register to COM and for sure it’s shown as we want.


-Implement Icon Overlay Handlers http://msdn.microsoft.com/en-us/library/windows/desktop/hh127442(v=vs.85).aspx

-Notify to shell http://msdn.microsoft.com/en-us/library/windows/desktop/bb762118(v=vs.85).aspx

-Creating Icon overlay in Python http://timgolden.me.uk/python/win32_how_do_i/add-my-own-icon-overlays.html

Các bài viết khác
Cùng lan toả
- Công việc chuyên môn là lập trình. - Thời gian làm việc đa số dùng internet cho nên cũng mong muốn chia sẻ những kiến thức và nhận định của mình cho mọi người về thế giới internet đầy rẫy tham sân si này. - Đã có vợ con. - Mọi liên hệ các bạn vui lòng email [email protected] hoặc [email protected]
Posts created 79

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top