A few questions --Actually you can save a step with PlotIconMethod. This code works for me. (‘Check’ is my own macro to shout if the argument is nonzero, you can replace with your own.)
View attachment 12896
C:pascal OSErr MakeIconCache (Handle *theCache, ProcPtr GetAnIcon, Ptr yourDataPtr ) = {0x303C, 0x0604, 0xABC9}; pascal OSErr LoadIconCache (const Rect *theRect, short alignment, long transform, Handle theSuite ) = {0x303C, 0x0606, 0xABC9}; pascal OSErr PlotIconSuite (const Rect *theRect, short alignment, short transform, Handle theSuite) = {0x303C, 0x0501, 0xABC9}; pascal OSErr DisposeIconSuite (Handle theSuite, Boolean disposeData) = {0x303C, 0x0302, 0xABC9}; pascal OSErr PlotIconMethod (const Rect *r, short alignment, short transform, ProcPtr method, Ptr data) = {0x303C, 0x0805, 0xABC9}; pascal Handle IconGetter(ResType type, Ptr data) { DTPBRec pb; short s, k; Handle h; short vRefNum; // open desktop db Check(GetVol(NULL, &vRefNum)); pb.ioNamePtr = NULL; pb.ioVRefNum = vRefNum; Check(PBDTOpenInform(&pb)); // get icon info switch (type) { case 'ICN#': s = kLargeIconSize; k = kLargeIcon; break; case 'icl4': s = kLarge4BitIconSize; k = kLarge4BitIcon; break; case 'icl8': s = kLarge8BitIconSize; k = kLarge8BitIcon; break; case 'ics#': s = kSmallIconSize; k = kSmallIcon; break; case 'ics4': s = kSmall4BitIconSize; k = kSmall4BitIcon; break; case 'ics8': s = kSmall8BitIconSize; k = kSmall8BitIcon; break; default: DebugStr("\punknown icon type"); } h = NewHandle(s); HLock(h); // just keep it locked til done // pb.ioDTRefNum = ... already populated pb.ioDTReqCount = s; pb.ioDTBuffer = *h; pb.ioIconType = k; pb.ioTagInfo = 0; pb.ioFileCreator = 'RSED'; // get icon for ResEdit pb.ioFileType = 'APPL'; // (only works for apps on indicated vRefNum!) Check(PBDTGetIconSync(&pb)); return h; } void main() { WindowPtr w; const Rect r = { 100, 100, 200, 200}; const Rect iconRect = { 10, 10, 42, 42 }; InitGraf(&thePort); InitFonts(); InitMenus(); InitWindows(); InitDialogs(NULL); w = NewCWindow(NULL, &r, "\p", true, documentProc, NULL, true, 0L); SetPort(w); Check( PlotIconMethod(&iconRect, 0, 0, IconGetter, NULL) ); while (!Button()) ; }
My ThinkC 5.0 doesn't seem to have the GetIconMethod(..) function declared in any of its available .h files.
I typed in the definition as you had it though and it seems to work because it does ultimately call my IconGetter function which I can debug with breakpoints.
However -- my IconGetter function's data value doesn't seem to have anything useful in it. I'm making use of it by actually passing a pointer to a structure instance in that last parameter of GetIconMethod(...). I'm just passing a DTPBRec pointer as the data since I have mine already constructed in the function that calls GetIconMethod(...).
I'll keep tinkering but this is very helpful thanks.