Hi,
I need to get the 'icl8' icon from a Mac OS X .icns file. The code I
use is as follows:
CFStringRef thePath = CFSTR("/Applications/Internet Explorer.app");
theAppURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
thePath, kCFURLPOSIXPathStyle, FALSE);
if (theAppURLRef != NULL)
{
theBundleRef = CFBundleCreate(kCFAllocatorDefault, theAppURLRef);
if (theBundleRef != NULL)
{
CFDictionaryRef theBundleInfoDict =
CFBundleGetInfoDictionary(theBundleRef);
CFStringRef theIcnsFileName = (CFStringRef)
CFDictionaryGetValue(theBundleInfoDict, CFSTR("CFBundleIconFile"));
theMutIcnsFileName = CFStringCreateMutableCopy(kCFAllocatorDefault,
0, theIcnsFileName);
CFStringTrim(theMutIcnsFileName, CFSTR(".icns"));
CFURLRef theIcnsURLRef = CFBundleCopyResourceURL(theBundleRef,
theMutIcnsFileName, CFSTR("icns"), NULL);
if (theIcnsURLRef != NULL)
{
OSErr err;
FSRef theRef;
FSSpec theSpec;
FSRefParam theRefParam;
bool found = false;
IconFamilyHandle theIconFamilyHandle = NULL;
found = CFURLGetFSRef(theIcnsURLRef, &theRef);
if (found)
{
theRefParam.ref = &theRef;
theRefParam.whichInfo = kFSCatInfoNone;
theRefParam.catInfo = NULL;
theRefParam.spec = &theSpec;
theRefParam.parentRef = NULL;
theRefParam.outName = NULL;
err = PBGetCatalogInfoSync(&theRefParam);
if (err == noErr)
err = ReadIconFile(theRefParam.spec, &theIconFamilyHandle);
if (err == noErr)
{
IconSuiteRef icl8Ref = NULL;
Handle icl8 = NULL;
err = IconFamilyToIconSuite (theIconFamilyHandle,
kSelectorLarge8Bit , &icl8Ref);
err = GetIconFromSuite(&icl8, icl8Ref, 'icl8');
.....
}
}
}
}
}
CFRelease(theAppURLRef);
CFRelease(theBundleRef);
CFRelease(theMutIcnsFileName);
CFRelease(theIcnsURLRef);
----
In this case (for Internet Explorer.app), GetIconFromSuite() returns
the desired 'icl8' data to the icl8 variable. It also works for
Sherlock.app. However for Mail.app, I get a NULL value for the icl8
variable (err is 0). Using IconComposer I open MacIE.icns and
app.icns. Both have the Large (32 x 32) icons. I assume they are the
8-bit large icons. I am not able to find any other tools to verify
that either the .icns file really does not have the 'icl8' data or
some thing is wrong with the code.
PowerBook G4 867Mhz
Mac OS 10.2.6
CW Pro 8.3, Carbon Target
Any help is appreciated,
an
Eric Albert - 31 Jan 2004 06:55 GMT
> In this case (for Internet Explorer.app), GetIconFromSuite() returns
> the desired 'icl8' data to the icl8 variable. It also works for
> Sherlock.app. However for Mail.app, I get a NULL value for the icl8
> variable (err is 0). Using IconComposer I open MacIE.icns and
> app.icns. Both have the Large (32 x 32) icons. I assume they are the
> 8-bit large icons.
Use icns Browser instead of Icon Computer. With icns Browser, you'll
see that Mail's app.icns file does not have an 8-bit 32x32 icon.
Hope this helps,
Eric

Signature
Eric Albert ejalbert@cs.stanford.edu
http://rescomp.stanford.edu/~ejalbert/
An Nguyen - 31 Jan 2004 18:46 GMT
> > In this case (for Internet Explorer.app), GetIconFromSuite() returns
> > the desired 'icl8' data to the icl8 variable. It also works for
[quoted text clipped - 8 lines]
> Hope this helps,
> Eric
Thanks. That did it!
an