Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get icon for .url files on Windows

Get icon for .url files on Windows

Scheduled Pinned Locked Moved General and Desktop
windowsicon
1 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hinst
    wrote on last edited by
    #1

    I noticed that SHGetFileInfoW function does not return icons for .url files on Windows... My app successfully obtains icons for regular .lnk shortcuts, but not for .url files. For example, shortcuts for Steam games have .url extension.

    For .url files I get blank-sheet icon. Ideas plz?
    Here is the code I use:

    HICON FileListData::loadHIcon(QString filePath)
    {
    	HICON result = 0;
    	auto filePathWideChars = new wchar_t[filePath.length() + 1];
    	filePath = filePath.replace('/', '\\');
    	filePath.toWCharArray(filePathWideChars);
    	filePathWideChars[filePath.length()] = 0;
    	auto fileInfo = new SHFILEINFO();
    	if (SHGetFileInfoW(filePathWideChars, FILE_ATTRIBUTE_NORMAL, fileInfo, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_LARGEICON))
    	{
    		result = fileInfo->hIcon;
    	}
    	delete[] filePathWideChars;
    	delete fileInfo;
    	return result;
    }
    
    void FileListData::burnIcon(int index)
    {
    	auto hicon = hicons[index];
    	QIcon icon = QIcon(QtWin::fromHICON(hicon));
    	icons.append(icon);
    }
    
    void FileListData::loadHIcons()
    {
    	hicons = new HICON[files.count()];
    	for (int i = 0; i < files.count(); i++)
    	{
    		auto fileInfo = files[i];
    //		if (fileInfo.isSymLink())
    //			fileInfo = QFileInfo(fileInfo.symLinkTarget());
    		const auto icon = loadHIcon(fileInfo.absoluteFilePath());
    		hicons[i] = icon;
    		if (iconLoadedEventReceiver != nullptr)
    			iconLoadedEventReceiver(i + 1);
    	}
    }
    
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved