DWORD_PTR SHGetFileInfo(
LPCTSTR pszPath,
DWORD dwFileAttributes,
SHFILEINFO *psfi,
UINT cbFileInfo,
UINT uFlags
);
|
DECLARE INTEGER SHGetFileInfo IN shell32;
STRING pszPath,;
LONG dwFileAttributes,;
STRING @psfi,;
LONG cbFileInfo,;
LONG uFlags
|
If SHGetFileInfo returns an icon handle (HICON) in the hIcon member of the SHFILEINFO structure pointed to by psfi.
Not so many applications in Visual FoxPro for this HICON handle I can think of. But there are two I am pretty sure about: displaying an icon in the System Tray, and displaying an icon inside the MessageBox dialog window.
The application is responsible for freeing the icon handle with DestroyIcon when it is no longer needed.
* * *
It seems that this function makes an addition to the system image list (aka Shell Icon Cache, HIMAGELIST), if the list has no element for the specified file type.
#DEFINE SHGFI_ICON 0x000000100
#DEFINE SHGFI_TYPENAME 0x000000400
#DEFINE SHGFI_USEFILEATTRIBUTES 0x000000010
#DEFINE FILE_ATTRIBUTE_NORMAL 0x00000080
*!*typedef struct _SHFILEINFO {
*!* HICON hIcon;
*!* int iIcon;
*!* DWORD dwAttributes;
*!* TCHAR szDisplayName[MAX_PATH];
*!* TCHAR szTypeName[80];
*!*} SHFILEINFO;
LOCAL cFilename, nBufsize, cBuffer, nFlags,;
nResult, hIcon
cFilename = ".xml"
nBufsize=1024
cBuffer = REPLICATE(CHR(0), nBufsize)
nFlags = BITOR(SHGFI_ICON,;
SHGFI_TYPENAME, SHGFI_USEFILEATTRIBUTES)
nResult = SHGetFileInfo(cFilename, FILE_ATTRIBUTE_NORMAL,;
@cBuffer, nBufsize, nFlags)
hIcon = buf2dword(SUBSTR(cBuffer, 1, 4))
IF hIcon <> 0
= DestroyIcon(hIcon)
ENDIF
All system icons can be accessed through this function and drawn, for example, on ListView ActiveX control:

* * *
As MSDN suggests, the SHGetFileInfo may not be the best way, even if the simplest, to retrieve an object`s icon. A more flexible and efficient way is to use IExtractIcon Interface. The Shell uses IExtractIcon to retrieve icons when it displays the contents of a folder. |