首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

有难求救!解决办法

2012-02-17 
有难求救!如何获取快捷方式图标的系统索引?大家帮帮忙吧!被领导骂了!心痛呀![解决办法]根据可执行文件名,

有难求救!
如何获取快捷方式图标的系统索引?
大家帮帮忙吧!
被领导骂了!
心痛呀!

[解决办法]
根据可执行文件名,获得这个文件的图标

SHFILEINFO shFileInfo = {0};

::SHGetFileInfo(szProcessPath,0,&shFileInfo,sizeof(SHFILEINFO),SHGFI_SYSICONINDEX);

shFileInfo.iIcon就是那个index


你是快捷方式??
根据快捷方式再获取文件的路径


[解决办法]
IShellLink* psl;
hres CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,IID_IShellLink, (void **)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
//Bind the ShellLink object to the Persistent File
hres = psl-> QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
//Get a UNICODE wide string wsz from the Link path
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Link, -1, wsz,MAX_PATH);

//Read the link into the persistent file
hres = ppf-> Load(wsz, 0);

if (SUCCEEDED(hres))
{
//Read the target information from the link object即“目标”
//UNC paths are supported (SLGP_UNCPRIORITY)
psl-> GetPath(Temp.GetBuffer(1024), 1024, NULL,SLGP_UNCPRIORITY);
Temp.ReleaseBuffer();
Info = Temp;
/*
//Read the arguments from the link object
psl-> GetArguments(Temp.GetBuffer(1024), 1024);
Temp.ReleaseBuffer();
Info += "\n " + Temp;
//Retrieves the description string for a shell link object即“备注”
psl-> GetDescription(Temp.GetBuffer(1024), 1024);
Temp.ReleaseBuffer();
Info += "\n " + Temp;

//Retrieves the name of the working directory from link object.即“起始位置”
psl-> GetWorkingDirectory(Temp.GetBuffer(1024), 1024);
Temp.ReleaseBuffer();
//Info += "\n " + Temp;
Info += Temp;
if(Info.IsEmpty())//当快捷方式文件指向文件夹时,解决文件重名覆盖的问题
{
psl-> GetPath(Temp.GetBuffer(1024), 1024, NULL,SLGP_UNCPRIORITY);
Temp.ReleaseBuffer();
Info = Temp;
}
*/
}
ppf-> Release();
}
psl-> Release();
}
[解决办法]
::SHGetFileInfo(szProcessPath,0,&shFileInfo,
sizeof(SHFILEINFO),SHGFI_ICON|SHGFI_LINKOVERLAY);返回的图标就带有一个向上的箭头了
[解决办法]
刚才我试了一下,使用SHGFI_ICON|SHGFI_LINKOVERLAY得到的icon还是无法显示出小箭头。
SHGFI_LINKOVERLAY
Modify SHGFI_ICON, causing the function to add the link overlay to the file 's icon. The SHGFI_ICON flag must also be set.
可能是我对这段英文理解错了??很抱歉。
但愿有用过的朋友能给予指正。

热点排行