3

I'm planning on building a hotkey-activated application launcher for Windows. I intend for it to be a pop-up grid of icons in which you can then click and launch what you need. I'd like for it to automatically scan the Start Menu and Desktop for program shortcuts and catalog them. However, I'm not sure of how to go about the icon retrieval process from the shortcuts/actual binaries and I was wondering if there are any libraries for C/C++ that handle this sort of thing? If not, how would I go about it otherwise?

delaccount992
  • 1,303
  • 3
  • 15
  • 21
  • An executable file can contain many icons - you specifically want the one that Windows displays in the Start menu or Explorer, correct? – Mark Ransom Jun 23 '11 at 18:58

5 Answers5

5

I think you want to use ExtractAssociatedIcon

See http://msdn.microsoft.com/en-us/library/ms648067%28v=VS.85%29.aspx

Rob W.
  • 362
  • 5
  • 18
1

resources extract is one such tool which extracts images from dll/ocx/exe files.

Well, if you do not want to use a closed source application, here is something with source, Icon Extractor

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • Interesting. I'd rather not use this as I'd have to be dependent on an external program and someone else's closed source code at that, but I think it'll work as a last resort if I can't find anything else. Thanks for the suggestion! – delaccount992 Jun 23 '11 at 18:50
1
  1. LoadLibraryEx - use LOAD_LIBRARY_AS_DATAFILE or LOAD_LIBRARY_AS_IMAGE_RESOURCE
  2. EnumResourceNames - to find the resource
  3. LoadImage/LoadIcon - to load the image/icon
dalle
  • 18,057
  • 5
  • 57
  • 81
1

You can use ExctractIconEx to load the specified icon from the executable. This article suggests checking for icon overrides in the registry at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons if compatibility with the shell is desired.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
1

ExtractIconEx. Full source code is in my open source project, file named icon.cpp. It supports expansion of system variables and getting a icon from an index, like %SYSTEMROOT%\system32\shell32.dll,43

Here is the guts of it :

HICON GoFindAnIcon(LPCTSTR path)
{
    HICON icon = 0;

    //not using our parent's icon
    if(_tcsicmp(L"parent", path))
    {
        icon = (HICON)LoadImage(0, path, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_LOADMAP3DCOLORS);
        if(!icon)
        {
            //Try something else
            TCHAR mypath[MAX_PATH];
            const TCHAR *cleanpath = path;
            const TCHAR *comma;             

            comma = _tcsrchr(path, ',');
            UINT index = 1;

            if(comma)
            {
                _tcsncpy(mypath, path, comma-path); //Can you exploit this buffer overflow ?
                mypath[comma-path] = TCHAR(0);

                index = _ttoi(comma+1);

                cleanpath = mypath;
            }

            ExtractIconEx(cleanpath, index, 0, &icon, 1);
        }
    }
    else
    {
        icon = GetParentProcessIcon();
    }

    return icon;
}
ixe013
  • 9,559
  • 3
  • 46
  • 77