Share via


SHGetFileInfo (Compact 2013)

3/28/2014

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

Syntax

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

Parameters

  • pszPath
    [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 that Windows Embedded Compact supports.

    Value

    Description

    FILE_ATTRIBUTE_INROM

    The file is a read-only operating-system (OS) file stored in ROM.

    FILE_ATTRIBUTE_ROMMODULE

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

  • psfi
    [in] Pointer to an SHFILEINFO structure that receives the file information.
  • cbFileInfo
    [in] Size, in bytes, of the SHFILEINFO structure that the psfi parameter points to.
  • uFlags
    [in] Flags that specify the file information to retrieve. This can be a combination of any 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. For Windows Embedded Compact, these are the same attributes that are obtained from IShellFolder::GetAttributesOf.

    SHGFI_DISPLAYNAME

    Retrieves the display name for the file. The name is copied to the szDisplayName member of the structure specified in psfi.

    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 that psfi specifies, 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_LARGEICON

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

    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 must not attempt to access the file that pszPath specifies. Rather, it should act as if the file that pszPath specifies exists with the file attributes passed in dwFileAttributes. This flag cannot be combined with the SHGFI_ATTRIBUTES flag.

Return Value

Returns a value whose meaning depends on the uFlags parameter. For example, if uFlags contains the SHGFI_EXETYPE flag, the return value specifies the type of the executable file as shown in the following table.

Value

Executable File Type

0

Non-executable file or an error condition

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

Windows application

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

SHGetFileInfo does not support the following values for uFlags:

  • SHGFI_ATTR_SPECIFIED
  • SHGFI_ADDOVERLAYS
  • SHGFI_EXETYPE
  • SHGFI_ICONLOCATION
  • SHGFI_LINKOVERLAY
  • SHGFI_OPENICON
  • SHGFI_OVERLAYINDEX
  • SHGFI_PIDL
  • SHGFI_SELECTED
  • SHGFI_SHELLICONSIZE

Remarks

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. Because Compact 2013 proceeds as if the file name and attributes are valid, you can obtain information about a file type by passing only the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.

For Windows Embedded Compact, the pszPath parameter must be a pointer to 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.

Code Example

The following code example demonstrates how to enable two-state file system icon animation.

Note

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

LRESULT CALLBACK TwoStateFileAnimProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    LPCTSTR szFileName                    = TEXT("myfile.xls");
    LRESULT lRet                          = 0;
    static SHFILEINFO s_sfiLarge          = {0};
    static SHFILEINFO s_sfiLargeSelected  = {0};
    static HIMAGELIST s_himlLarge         = NULL;
    static HIMAGELIST s_himlLargeSelected = NULL;
    switch (message)
    {
        case WM_CREATE:
            // Cache the file information and the imagelist.
            // Get the large default icon for the file.
            s_himlLarge = (HIMAGELIST)SHGetFileInfo(szFileName, 0, &s_sfiLarge, sizeof(s_sfiLarge), SHGFI_SYSICONINDEX|SHGFI_LARGEICON);
            // Get the large selected icon for the file.
            s_himlLargeSelected = (HIMAGELIST)SHGetFileInfo(szFileName, 0, &s_sfiLargeSelected, sizeof(s_sfiLargeSelected), SHGFI_SYSICONINDEX|SHGFI_LARGEICON|SHGFI_SELECTICON);
            break;
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC hdc = BeginPaint(hwnd, &ps);
                // Draw the file icon in the selected state.
                ImageList_Draw(s_himlLargeSelected, s_sfiLargeSelected.iIcon, hdc, 0, 0, ILD_TRANSPARENT);
                // Draw the file icon in the default state.
                ImageList_Draw(s_himlLarge, s_sfiLarge.iIcon, hdc, 0, 100, ILD_TRANSPARENT);
                EndPaint(hwnd, &ps);
                break;
            }
    }
    return lRet;
}

Requirements

Header

shellapi.h

See Also

Reference

Shell Functions
DestroyIcon
SHFILEINFO