Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

SHGetFileInfo does not retrieve the correct icon path


  • Please log in to reply
No replies to this topic
  • Guests
  • Last active:
  • Joined: --
Hi,

I'm having hard time retrieving the correct path of an associated icon of folder. The following code retrieves the icon path of the folder where the script is located. And in Windows 7 it yields Path: C:\Windows\system32\imageres.dll, Icon Number: 1, which is wrong for a folder icon. If the user has chaned the folder icon via Explorer -> Properties -> Customze -> Change Icon, then it returns the correct path and the number.

Can somebody tell the problem? The following code uses[CLASS] DllStruct (AHK 1.1) by just me. Thanks.
#include <Class_DllStruct>  ;http://www.autohotkey.com/forum/topic74240.html
path := A_ScriptDIr 	
def__SHFILEINFO := "
(LTrim Join
  HICON hIcon;
  int   iIcon;
  DWORD dwAttributes;
  TCHAR szDisplayName[260];
  TCHAR szTypeName[80];
)"
_SHFILEINFO := new DllStruct(def__SHFILEINFO)	
if DllCall("Shell32\SHGetFileInfo" . (A_IsUnicode ? "W":"A")
	, "str", path 
	, "uint", 0
	, ptr, _SHFILEINFO.GetPtr()
	, "uint", _SHFILEINFO.GetSize()
	, "uint", 0x000000100|0x000001000	; SHGFI_ICONLOCATION|SHGFI_ICON
	, ptr) 	
{
	msgbox % "Path:`t`t" _SHFILEINFO.szDisplayName "`n"
		. "Icon Number:`t" _SHFILEINFO.iIcon "`n"
		. "hIcon:`t`t" _SHFILEINFO.hIcon
} else
	msgbox not found