刚查了msdn,看来你的代码是正确的。我以前只用过Extracticon,没想到shgetfileino
也可以取文件的图标。真是不好意思啦!!!!
SHGetFileInfo
WINSHELLAPI DWORD WINAPI SHGetFileInfo(
; ; LPCTSTR pszPath,
; ; DWORD dwFileAttributes,
; ; SHFILEINFO FAR *psfi,
; ; UINT cbFileInfo,
; ; UINT uFlags
);
Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root.
Returns a value whose meaning depends on the uFlags parameter. If uFlags contains the SHGFI_EXETYPE flag, the return value specifies the type of the executable file. It will be one of the following values: Value ;Executable File Type
0 ;Nonexecutable file or an error condition
LOWORD = NE or PE and HIWORD = 3.0, 3.5, or 4.0 ;Windows application
LOWORD = MZ and HIWORD = 0 ;MS-DOS .exe, .com, or .bat file
LOWORD = PE and HIWORD = 0 ;Win32 console application
If uFlags contains SHGFI_SYSICONINDEX, the return value is the handle to the system image list that contains the large icon images. If SHGFI_SMALLICON is included with SHGFI_SYSICONINDEX, the return value is the handle to the image list that contains the small icon images.
If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return value is nonzero if successful, or zero otherwise.
pszPath
Address of a buffer that contains the path and file name. Both absolute and relative paths are valid.
If the uFlags parameter includes the SHGFI_PIDL flag, this parameter must be the address of an ITEMIDLIST (PIDL) structure that contains the list of item identifiers that uniquely identifies the file within the shell's namespace. The PIDL must be a fully qualified PIDL. Relative PIDLs are not allowed.
If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, this parameter does not have to be a valid file name. The function will proceed as if the file exists with the specified name and with the file attributes passed in the dwFileAttributes parameter. This allows you to obtain information about a file type by passing just the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.
This string can use either short (the 8.3 form) or long file names.
dwFileAttributes
Combination of one or more file attribute flags (FILE_ATTRIBUTE_ values). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored.
psfi
Address of a SHFILEINFO structure to receive the file information.
cbFileInfo
Size, in bytes, of the SHFILEINFO structure pointed to by the psfi parameter.
uFlags
Flags that specify the file information to retrieve. This parameter can be a combination of the following values: SHGFI_ATTR_SPECIFIED ;Modifies SHGFI_ATTRIBUTES. Indicates that the dwAttributes member of the SHFILEINFO structure at psfi contains the specific attributes that are desired. These attributes will be passed to IShellFolder::GetAttributesOf. If this flag is not specified, 0xFFFFFFFF will be passed to GetAttributesOf, requesting all attributes. This flag cannot be specified with the SHGFI_ICON flag. ;
SHGFI_ATTRIBUTES ;Retrieve the item attributes. The attributes are copied to the dwAttributes member of the structure specified in the psfi parameter. These are the same attributes that are obtained from IShellFolder::GetAttributesOf. ;
SHGFI_DISPLAYNAME ;Retrieve the display name for the file. The name is copied to the szDisplayName member of the structure specified in psfi. The returned display name uses the long file name, if there is one, rather than the 8.3 form of the file name. ;
SHGFI_EXETYPE ;Retrieve the type of the executable file if pszPath identifies an executable file. This flag cannot be specified with any other flags. ;
SHGFI_ICON ;Retrieve the handle to the icon that represents the file and the index of the icon within the system image list. The handle is copied to the hIcon member of the structure specified by psfi, and the index is copied to the iIcon member. The return value is the handle to the system image list. ;
SHGFI_ICONLOCATION ;Retrieve the name of the file that contains the icon representing the file. The name is copied to the szDisplayName member of the structure specified in psfi. ;
SHGFI_LARGEICON ;Modify SHGFI_ICON, causing the function to retrieve the file's large icon. ;
SHGFI_LINKOVERLAY ;Modify SHGFI_ICON, causing the function to add the link overlay to the file's icon. ;
SHGFI_OPENICON ;Modify SHGFI_ICON, causing the function to retrieve the file's open icon. A container object displays an open icon to indicate that the container is open. ;
SHGFI_PIDL ;Indicate that pszPath is the address of an ITEMIDLIST structure rather than a path name. ;
SHGFI_SELECTED ;Modify SHGFI_ICON, causing the function to blend the file's icon with the system highlight color. ;
SHGFI_SHELLICONSIZE ;Modify SHGFI_ICON, causing the function to retrieve a shell-sized icon. If this flag is not specified the function sizes the icon according to the system metric values. ;
SHGFI_SMALLICON ;Modify SHGFI_ICON, causing the function to retrieve the file's small icon. ;
SHGFI_SYSICONINDEX ;Retrieve the index of the icon within the system image list. The index is copied to the iIcon member of the structure specified by psfi. The return value is the handle to the system image list. ;
SHGFI_TYPENAME ;Retrieve the string that describes the file's type. The string is copied to the szTypeName member of the structure specified in psfi. ;
SHGFI_USEFILEATTRIBUTES ;Indicates that the function should not attempt to access the file specified by pszPath. Rather, it should act as if the file specified by pszPath exists with the file attributes passed in dwFileAttributes. This flag cannot be combined with the SHGFI_ATTRIBUTES, SHGFI_EXETYPE, or SHGFI_PIDL flags. ;
--------------------------------------------------------------------------------