SHFILEINFO&&SHGetFileInfo

SHFILEINFO fileInfo;
SHGetFileInfo (
    "C://boot.ini", NULL,
    &fileInfo,
    sizeof(SHFILEINFO),
    SHGFI_ICON|SHGFI_TYPENAME);
 
cout << fileInfo . szTypeName << " 文件 " << endl ;
cout << "0x" << hex << fileInfo . hIcon << endl ;
cout << "0x" << hex << fileInfo . dwAttributes << endl ;
 
/*  输出:
    配置设置文件
    0x09FC07B5
    0x40400177
*/
 
//Handle to the icon that represents the file.
//You are responsible for destroying this handle
//with DestroyIcon when you no longer need it.
DestroyIcon ( fileInfo . hIcon );
______________________________
SHFILEINFO Structure----Contains information about a file object.
typedef struct _SHFILEINFO {
  HICON hIcon;
  int   iIcon;
  DWORD dwAttributes;
  TCHAR szDisplayName[MAX_PATH];
  TCHAR szTypeName[80];
} SHFILEINFO;

Members

hIcon

Type: HICON

A handle to the icon that represents the file. You are responsible for destroying this handle with DestroyIcon when you no longer need it.

 

iIcon

Type: int

The index of the icon image within the system image list.

 

dwAttributes

Type: DWORD

An array of values that indicates the attributes of the file object. For information about these values, see the IShellFolder::GetAttributesOf method.

 

szDisplayName

Type: TCHAR[MAX_PATH]

A string that contains the name of the file as it appears in the Windows Shell, or the path and file name of the file that contains the icon representing the file.

 

szTypeName

Type: TCHAR[80]

A string that describes the type of file.

----------------------------------------------

SHGetFileInfo Function

Retrieves information about an object in the file system, such as a file, folder, directory, or drive root.

 

DWORD_PTR SHGetFileInfo(
  __in     LPCTSTR pszPath,
  DWORD dwFileAttributes,
  __inout  SHFILEINFO *psfi,
  UINT cbFileInfo,
  UINT uFlags
);

 

pszPath [in]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH 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

Type: DWORD

A combination of one or more file attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored.

psfi [in, out]

Type: SHFILEINFO*

Pointer to a SHFILEINFO structure to receive the file information.

 

cbFileInfo

Type: UINT

The size, in bytes, of the SHFILEINFO structure pointed to by the psfi parameter.

 

uFlags

Type: UINT

The flags that specify the file information to retrieve. This parameter can be a combination of the following values.

SHGFI_ADDOVERLAYS (0x000000020)

Version 5.0. Apply the appropriate overlays to the file's icon. The SHGFI_ICON flag must also be set.

SHGFI_ATTR_SPECIFIED (0x000020000)

Modify SHGFI_ATTRIBUTES to indicate that the dwAttributes member of the SHFILEINFO structure at psfi contains the specific attributes that are desired. These attributes are passed to IShellFolder::GetAttributesOf. If this flag is not specified, 0xFFFFFFFF is passed to IShellFolder::GetAttributesOf, requesting all attributes. This flag cannot be specified with the SHGFI_ICON flag.

SHGFI_ATTRIBUTES (0x000000800)

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 (0x000000200)

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 (0x000002000)

Retrieve the type of the executable file if pszPath identifies an executable file. The information is packed into the return value. This flag cannot be specified with any other flags.

SHGFI_ICON (0x000000100)

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.

SHGFI_ICONLOCATION (0x000001000)

Retrieve the name of the file that contains the icon representing the file specified by pszPath, as returned by the IExtractIcon::GetIconLocation method of the file's icon handler. Also retrieve the icon index within that file. The name of the file containing the icon is copied to the szDisplayName member of the structure specified by psfi. The icon's index is copied to that structure's iIcon member.

SHGFI_LARGEICON (0x000000000)

Modify SHGFI_ICON, causing the function to retrieve the file's large icon. The SHGFI_ICON flag must also be set.

SHGFI_LINKOVERLAY (0x000008000)

Modify SHGFI_ICON, causing the function to add the link overlay to the file's icon. The SHGFI_ICON flag must also be set.

SHGFI_OPENICON (0x000000002)

Modify SHGFI_ICON, causing the function to retrieve the file's open icon. Also used to modify SHGFI_SYSICONINDEX, causing the function to return the handle to the system image list that contains the file's small open icon. A container object displays an open icon to indicate that the container is open. The SHGFI_ICON and/or SHGFI_SYSICONINDEX flag must also be set.

SHGFI_OVERLAYINDEX (0x000000040)

Version 5.0. Return the index of the overlay icon. The value of the overlay index is returned in the upper eight bits of the iIcon member of the structure specified by psfi. This flag requires that the SHGFI_ICON be set as well.

SHGFI_PIDL (0x000000008)

Indicate that pszPath is the address of an ITEMIDLIST structure rather than a path name.

SHGFI_SELECTED (0x000010000)

Modify SHGFI_ICON, causing the function to blend the file's icon with the system highlight color. The SHGFI_ICON flag must also be set.

SHGFI_SHELLICONSIZE (0x000000004)

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. The SHGFI_ICON flag must also be set.

SHGFI_SMALLICON (0x000000001)

Modify SHGFI_ICON, causing the function to retrieve the file's small icon. Also used to modify SHGFI_SYSICONINDEX, causing the function to return the handle to the system image list that contains small icon images. The SHGFI_ICON and/or SHGFI_SYSICONINDEX flag must also be set.

SHGFI_SYSICONINDEX (0x000004000)

Retrieve the index of a system image list icon. If successful, the index is copied to the iIcon member of psfi. The return value is a handle to the system image list. Only those images whose indices are successfully copied to iIcon are valid. Attempting to access other images in the system image list will result in undefined behavior.

SHGFI_TYPENAME (0x000000400)

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 (0x000000010)

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.

Return Value

Type: DWORD_PTR

Returns a value whose meaning depends on the uFlags parameter.

If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return value is nonzero if successful, or zero otherwise.

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.

 

 

Return code--------------------------------------------------------------------Description

 

0

Nonexecutable file or an error condition.

LOWORD = NE or PE and HIWORD = Windows version

Windows application.

LOWORD = MZ and HIWORD = 0

MS-DOS .exe or .com file

LOWORD = PE and HIWORD = 0

Console application or .bat file


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值