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/a开发者_StackOverflowctual 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?
I think you want to use ExtractAssociatedIcon
See http://msdn.microsoft.com/en-us/library/ms648067%28v=VS.85%29.aspx
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
- LoadLibraryEx - use
LOAD_LIBRARY_AS_DATAFILE
orLOAD_LIBRARY_AS_IMAGE_RESOURCE
- EnumResourceNames - to find the resource
- LoadImage/LoadIcon - to load the image/icon
You may find this article useful: http://www.codeproject.com/KB/shell/shellicon.aspx
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;
}
精彩评论