SHGetFileInfo

Jamie jamie at nospam.net
Tue May 27 16:53:04 EDT 2003


Many thanks, Thomas.

Jamie

"Thomas Heller" <theller at python.net> wrote in message
news:65nx0zmw.fsf at python.net...
> "Jamie" <jamie at nospam.net> writes:
>
> > Hi all,
> >
> > Does anyone have an example of how to make this call using either the
ctypes
> > module or the win32 python extensions?
>
> I don't find it in the win32 extensions, so here is the ctypes version,
> which prints this (WinXP pro german):
>
>     1
>     0x40400177L
>     'python.exe'
>     'Anwendung'
>
> Thomas
> -----
> from ctypes import *
>
> MAX_PATH = 260
> HICON = c_int
>
> class SHFILEINFO(Structure):
>     _fields_ = [("hIcon", HICON),
>                 ("iIcon", c_int),
>                 ("dwAttributes", c_uint),
>                 ("szDisplayName", c_char * MAX_PATH),
>                 ("szTypeName", c_char * 80)]
>
> SHGFI_ICON              = 0x000000100
> SHGFI_DISPLAYNAME       = 0x000000200
> SHGFI_TYPENAME          = 0x000000400
> SHGFI_ATTRIBUTES        = 0x000000800
> SHGFI_ICONLOCATION      = 0x000001000
> SHGFI_EXETYPE           = 0x000002000
> SHGFI_SYSICONINDEX      = 0x000004000
> SHGFI_LINKOVERLAY       = 0x000008000
> SHGFI_SELECTED          = 0x000010000
> SHGFI_ATTR_SPECIFIED    = 0x000020000
> SHGFI_LARGEICON         = 0x000000000
> SHGFI_SMALLICON         = 0x000000001
> SHGFI_OPENICON          = 0x000000002
> SHGFI_SHELLICONSIZE     = 0x000000004
> SHGFI_PIDL              = 0x000000008
> SHGFI_USEFILEATTRIBUTES = 0x000000010
>
>
> shfileinfo = SHFILEINFO()
>
> import sys
>
> flags = SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES
> print windll.shell32.SHGetFileInfo(sys.executable,
>                                    0,
>                                    byref(shfileinfo),
>                                    sizeof(shfileinfo),
>                                    flags)
>
> print hex(shfileinfo.dwAttributes)
> print repr(shfileinfo.szDisplayName)
> print repr(shfileinfo.szTypeName)
> -----






More information about the Python-list mailing list