SHGetFileInfo(获取文件信息)

可以获取文件系统中的文件、目录、驱动器的信息。

语法:

WINSHELLAPI DWORD WINAPI SHGetFileInfo(
  LPCTSTR pszPath, 
  DWORD dwFileAttributes, 
  SHFILEINFO FAR* psfi, 
  UINT cbFileInfo, 
  UINT uFlags 
);


参数:

[in] Pointer to a buffer that contains the path and file name. Both absolute and relative paths are valid. For more information, see Remarks.

dwFileAttributes

[in] Combination of one or more file attribute flags (FILE_ATTRIBUTE_* values). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored.

The following table shows the additional values supported by Windows Embedded CE.

Value Description

FILE_ATTRIBUTE_INROM

The file is an operating system (OS) file stored in ROM. These files are read-only.

FILE_ATTRIBUTE_ROMMODULE

The file is an operating system file stored in ROM, designed to execute in place. In other words, code from this file is executed directly from ROM, rather than being first copied to RAM. The CreateFile function cannot be used to access this file. Use the LoadLibrary and CreateProcess functions instead.

psfi

[in] Pointer to a SHFILEINFO structure to receive the file information.

cbFileInfo

[in] Size, in bytes, of the SHFILEINFO structure pointed to by the psfi parameter.

uFlags

[in] 指定要获取的文件信息. It can be a combination of the values in the following table.

Value Description

SHGFI_ATTRIBUTES

Retrieves the item attributes. The attributes are copied to the dwAttributes member of the structure specified in the psfi parameter.

SHGFI_DISPLAYNAME

返回文件的显示名称. The name is copied to the szDisplayName member of the structure specified in psfi.

SHGFI_EXETYPE

如果指定的是一个可执行文件,返回可执行文件的类型. This flag cannot be specified with any other flags.

SHGFI_ICON

Retrieves 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. You must call the DestroyIcon function on this icon handle.

SHGFI_ICONLOCATION

Retrieves 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

Modifies SHGFI_ICON, causing the function to retrieve the file's large icon.

SHGFI_LINKOVERLAY

Modifies SHGFI_ICON, causing the function to add the link overlay to the file's icon.

SHGFI_OPENICON

Modifies 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

For Windows CE 1.0 through 2.01 and for Windows Embedded CE Handheld PC Edition version 3.0 and Windows Embedded CE Handheld PC Professional Edition version 3.0, indicates that pszPath is the address of an ITEMIDLIST structure rather than a path name.

SHGFI_SELECTED

Modifies SHGFI_ICON, causing the function to blend the file's icon with the system highlight color.

SHGFI_SMALLICON

Modifies SHGFI_ICON, causing the function to retrieve the file's small icon.

SHGFI_SYSICONINDEX

Retrieves 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

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

SHGFI_SELECTICON

Modifies SHGFI_ICON, causing the function to retrieve the file's icon in the selected state.

If SHGetFileInfo function cannot find a registered select icon for a file when SHGFI_SELECTICON was requested, it will return the default icon.

Note:
This flag is supported only for a Windows Mobile device.

SHGFI_SHELLICONSIZE

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

返回值:

Returns a value with a meaning that depends on the uFlags parameter. If uFlags contains the SHGFI_EXETYPE flag, the return value specifies the type of the executable file. The following table shows the possible values.

Value Executable File Type

0

没有可执行文件或错误条件

Low-order word = NE or PE and high-order word = 3.0, 3.5, or 4.0

Windows(窗体)应用程序

Low-order word = MZ and high-order word = 0

MS-DOS .exe, .com, or .bat file

Low-order word = PE and high-order word = 0

Microsoft Win32®-based控制台应用程序

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.

 

备注:

If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, the pszPath parameter does not have to be a valid file name. The function proceeds as if the file exists with the specified name and with the file attributes passed in the dwFileAttributes parameter. This enables you to obtain information about a file type by passing just the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.

For Windows CE 2.10 and later, SHGetFileInfo does not support the following values for uFlags:

SHGFI_EXETYPE

SHGFI_ICONLOCATION

SHGFI_LINKOVERLAY

SHGFI_OPENICON

SHGFI_SELECTED

SHGFI_SHELLICONSIZE

Also for Windows CE 2.10 and later, SHGetFileInfo supports the SHGFI_PIDL flag only for Windows Embedded CE Handheld PC Edition version 3.0 and Windows Embedded CE Handheld PC Professional Edition version 3.0.

 

你可能感兴趣的:(C#,C,C++)