关于快捷方式的图标

戴晶晶jjyyis 2003-04-04 05:56:59
CComPtr<IShellLink> slink;
slink.CoCreateInstance(CLSID_ShellLink));

CComPtr<IPersistFile> pFile;
slink.QueryInterface<IPersistFile>(&pFile);

pFile->Load(fname->AllocSysString(), STGM_READ));
slink->Resolve(hWnd, SLR_NOUPDATE);

CString str;
GameListItem Item;
slink->GetDescription(str.GetBuffer(MAX_PATH), MAX_PATH));
str.ReleaseBuffer();
strcpy(Item.Description, str);

slink->GetArguments(str.GetBuffer(MAX_PATH), MAX_PATH));

str.ReleaseBuffer();
strcpy(Item.Argument, str);
slink->GetPath(str.GetBuffer(MAX_PATH), MAX_PATH, NULL, SLGP_UNCPRIORITY))
str.ReleaseBuffer();
strcpy(Item.Path, str);

int index;
slink->GetIconLocation(str.GetBuffer(MAX_PATH), MAX_PATH, &index));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在这里怎么也得不到图标的路径。前边的函数都正确
想尽所有的办法了,就是不行么!!!!!!
帮忙啊
...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
戴晶晶jjyyis 2003-04-07
  • 打赏
  • 举报
回复
JennyVenus() 大哥(大姐),我的问题是如何获取快捷方式的图标,不是如何创建快捷方式,并保存他的图标。

我自己解决了,不过还是多谢你的帮助,呵呵
用户 昵称 2003-04-05
  • 打赏
  • 举报
回复
some code to FYI

Following sample code creates a shortcut and sets the shortcut's icon to an icon contained in shell32.dll:
/*PARAMETERS
fname_to_create_link = (e.g.) "c:\\mytextfile.txt"
lnk_fname = (e.g.) "yourname.lnk"
*/

void CreateLinkThenChangeIcon(LPTSTR fname_to_create_link,
LPTSTR lnk_fname)
{
HRESULT hres;
IShellLink *psl = NULL;
IPersistFile *pPf = NULL;
WORD wsz[256];
TCHAR buf[256];
int id;
LPITEMIDLIST pidl;

hres = CoCreateInstance( CLSID_ShellLink,

NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(LPVOID*)&psl);
if(FAILED(hres))
goto cleanup;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
if(FAILED(hres))
goto cleanup;
hres = psl->SetPath(fname_to_create_link);
if(FAILED(hres))

goto cleanup;
//place the shortcut on the desktop
SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP, >pidl);

SHGetPathFromIDList(pidl, buf);

lstrcat(buf,"\\");
lstrcat(buf,lnk_fname);

MultiByteToWideChar(CP_ACP, 0, buf, -1, wsz, MAX_PATH);

hres = pPf->Save(wsz, TRUE);

if(FAILED(hres))

goto cleanup;

GetSystemDirectory(buf, 256);

lstrcat(buf,"\\shell32.dll");

hres = psl->SetIconLocation(buf, 1);

if(FAILED(hres))

goto cleanup;

hres = psl->GetIconLocation(buf, 256, &id);

if(FAILED(hres))

goto cleanup;

pPf-&Save(wsz, TRUE);

cleanup:

if(pPf)

pPf->Release();

if(psl)

psl->Release();

}
It works!
戴晶晶jjyyis 2003-04-04
  • 打赏
  • 举报
回复
急啊!!!
戴晶晶jjyyis 2003-04-04
  • 打赏
  • 举报
回复
在线等待啊

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧