PDA

View Full Version : Qt app LNK: Icon in taskbar is the LNK icon, not app icon



ddonate
28th January 2021, 11:53
Hi,

I have a Qt app and I need to save in runtime a LNK to my .exe file in user desktop
The LNK icon must be a pixmap I have in runtime, different from my .EXE icon
When I use that LNK (there can be more than one with different icons), my app is launched but the icon in taskbar is the LNK icon, not my app icon

How can I solve that?

I am creating a link with this snipped code:


QString sPathTarget = [MY_EXE_PATH];
QString sLinkName = "link name";
QString sLinkArguments = "link arguments";
QString sLinkIcon = [MY_ICON_PATH]; // This icon will be the LNK icon, but also the icon my app has in the taskbar when launched from the LNK

WCHAR pathDesktop[MAX_PATH];
HRESULT result = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, pathDesktop);

if (SUCCEEDED(result)) {
QString linkPath = QDir(QString::fromWCharArray(pathDesktop)).absolut eFilePath(QString("%1.lnk").arg(sLinkName));

CoInitialize(NULL);
IShellLinkW* shellLink = NULL;
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
if (SUCCEEDED(result)) {
shellLink->SetPath(sPathTarget.toStdWString().c_str());
shellLink->SetArguments(sLinkArguments.toStdWString().c_str() );
shellLink->SetIconLocation(sLinkIcon.toStdWString().c_str(), 0);
IPersistFile* persistFile;
result = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);

if (SUCCEEDED(result)) {
result = persistFile->Save(linkPath.toStdWString().c_str(), TRUE);

persistFile->Release();

bRet = true;
}
shellLink->Release();
}
}

Thanks,
Diego

d_stranz
28th January 2021, 15:32
These are Windows questions, not Qt questions. You need to find a Windows forum to post them. Please do not post non-Qt questions here.

ddonate
29th January 2021, 19:32
These are Windows questions, not Qt questions. You need to find a Windows forum to post them. Please do not post non-Qt questions here.

Sorry, I thought something I am doing in the Qt app was the cause...