Hi,

I have a Qt app and I need to save in runtime a link to my .exe file (with some arguments) in user desktop The icon must be a pixmap I have in runtime. Can I use this pixmap somehow as the link icon or must I save the pixmap to a .ico file?

Another doubt: when I create the link with an icon path my app icon is changed to that icon... Can I avoid it? I want an icon for the link different from my app icon

I am (successfully) creating a link with this snipped code:

Qt Code:
  1. QString sPathTarget = [MY_EXE_PATH];
  2. QString sLinkName = "link name";
  3. QString sLinkArguments = "link arguments";
  4. QString sLinkIcon = [MY_EXE_PATH]; // Here: can I use the pixmap I have in runtime?
  5.  
  6. WCHAR pathDesktop[MAX_PATH];
  7. HRESULT result = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, pathDesktop);
  8.  
  9. if (SUCCEEDED(result)) {
  10. QString linkPath = QDir(QString::fromWCharArray(pathDesktop)).absoluteFilePath(QString("%1.lnk").arg(sLinkName));
  11.  
  12. CoInitialize(NULL);
  13. IShellLinkW* shellLink = NULL;
  14. result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
  15. if (SUCCEEDED(result)) {
  16. shellLink->SetPath(sPathTarget.toStdWString().c_str());
  17. shellLink->SetArguments(sLinkArguments.toStdWString().c_str());
  18. shellLink->SetIconLocation(sLinkIcon.toStdWString().c_str(), 0);
  19. IPersistFile* persistFile;
  20. result = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);
  21.  
  22. if (SUCCEEDED(result)) {
  23. result = persistFile->Save(linkPath.toStdWString().c_str(), TRUE);
  24.  
  25. persistFile->Release();
  26.  
  27. bRet = true;
  28. }
  29. shellLink->Release();
  30. }
  31. }
To copy to clipboard, switch view to plain text mode 
Thanks,
Diego