涉及到两个函数:第一个是根据全路径文件名称来获取内置图标;第二个是根据文件名来获取全路径名称(采用注册表内置环境变量判断)

函数一:获取文件的全路径名称,返回的变量fullpath_res就是全路径文件名称;

 ;**********************************
;获取文件的全路径,通过注册表的环境变量来判断
;**********************************
getfullpath(filename)
{
    IfNotExist, % filename
    {
        RegRead , temp_path, HKLM, SYSTEM\ControlSet001\Control\Session Manager\Environment, Path ;读取原有
        loop,parse,% temp_path, % ";"
        {
                temp1:=trim(a_loopfield)
                StringReplace, temp1, temp1, % "%systemroot%", % A_WinDir
                
                ;判断结尾是否为\标记;
                temp2:=SubStr(temp1,0)    
                if (temp2="\")
                {
                    temp2:=temp1
                }
                else
                {
                    temp2:=temp1 . "\"
                }

                ifexist, % temp2 . filename
                {
                fullpath_res:=temp2 . filename
                break
                }
        }
        
    }
    else
    {
       fullpath_res:=filename
    }
return fullpath_res
}

?

函数二:根据全路径文件名称来获取图标,;

 ;***********************************************************
;获取文件图标的函数,必须采用全路径而且文件必须存在,返回值为g_hicon
;返回值g_hicon就是返回图标;
;***********************************************************
get_file_icon(this_fullpathname){
    VarSetCapacity(fileinfo, fisize := A_PtrSize + 688)
    ;~ ; 获取文件的图标.
   
 if DllCall("c:\windows\system32\shell32\SHGetFileInfoW", "wstr", 
this_fullpathname, "uint", 0, "ptr", &fileinfo, "uint", fisize, 
"uint", 0x100)
    {
        g_hicon_temp := NumGet(fileinfo, 0, "ptr")
        g_hicon = HICON:%g_hicon_temp%  ;这句是个关键,这样该变量可以直接进入函数里面使用,否则带HICON:%g_hicon_temp%这样的无法进入函数
    }
return g_hicon
}

?