获取系统文件关联图标

import tkinter
from win32com.shell import shell, shellcon
from win32con import FILE_ATTRIBUTE_NORMAL
 
def extension_to_bitmap(extension):
    """dot is mandatory in extension"""
 
    flags = shellcon.SHGFI_SMALLICON | \
            shellcon.SHGFI_ICON | \
            shellcon.SHGFI_USEFILEATTRIBUTES
 
    retval, info = shell.SHGetFileInfo(extension,
                             FILE_ATTRIBUTE_NORMAL,
                             flags)
    # non-zero on success
    assert retval
 
    hicon, iicon, attr, display_name, type_name = info
 
    # Get the bitmap
    icon = wx.EmptyIcon()
    icon.SetHandle(hicon)
    return wx.BitmapFromIcon(icon)

 

posted @ 2014-03-14 17:01  @烈风  阅读(344)  评论(0编辑  收藏  举报