函数原型:
WINSHELLAPI DWORD WINAPI SHGetFileInfo
( LPCTSTR pszPath , DWORD dwFileAttributes , SHFILEINFO FAR *psfi , UINT cbFileInfo , UINT uFlags );
其中,当uFlags使用 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. You must call the DestroyIcon function on this icon handle.
否则会造成内存泄露,SHGetFileInfo再使用时就获取不到图标.
遇到不解的问题,首先查MSDN...
另外,如果使用这个函数获取其它信息,比如文件类型,那么参数里就不要再使用 SHGFI_ICON,因为这样如果不注意,后面没有DestroyIcon,同样会引起图标消失的问题
本文介绍了Windows API函数SHGetFileInfo的使用方法,特别是当使用SHGFI_ICON标志获取文件图标时,如何正确释放图标资源以避免内存泄漏,并确保后续调用能正常获取图标。

51

被折叠的 条评论
为什么被折叠?



