Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Data files with associated icons and owners. Message-ID: <47694@apple.Apple.COM> Date: 3 Jan 91 03:27:08 GMT References: <2075@njitgw.njit.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 104 mg5184@mars.njit.edu (Michael Gaines) writes: > Here's the deal. I've been racking my brains with this and the >limited number of resources I've had available to me. I'm writing a >program (no kidding) in which data files are created. I want to know how >to copy an icon from my ICN# list to be the desktop icon for my data >file. ALSO, I would have to change the owner of the data file. Please, >don't kick me if this is something too obvious. I thought there was a >resource fork at work here, but my data files from MathCAD and Word have >unique icons and no resource forks. You don't have to do any copying of icons since the Finder is the one that manages all the icons. You just have to supply them (and a couple of other resources) as part of your application. Suppose you have an application and document with the following types/creators: application document type APPL ADOC creator MYAP MYAP Your application needs to contain 5 resources to manage all this: a bundle resource (BNDL), 2 icons (ICN#) and 2 file reference resources (FREF). Putting it all together looks like this in MPW's Rez: resource 'BNDL' (128) { 'MYAP', /* application's creator */ 0, /* owner ID */ { 'ICN#', /* list of associated icons */ { 0, 128; /* application's local ID, resource ID */ 1, 129; /* document's local ID, resource ID */ }; 'FREF', /* list of associated file references */ { 0, 128; /* application's local ID, resource ID */ 1, 129; /* document's local ID, resource ID */ }; } }; resource 'ICN#' (128) { /* application's icon */ { $"xxxxxxx"; /* icon data */ $"xxxxxxx" /* icon mask */ } }; resource 'ICN#' (129) { /* document's icon */ { $"xxxxxxx"; /* icon data */ $"xxxxxxx" /* icon mask */ } }; resource 'FREF' (128) { /* application's file reference */ 'APPL' /* application's file type */ 0, /* application icon's local ID */ "" /* associated file (none) */ }; resource 'FREF' (129) { /* document's file reference */ 'ADOC', /* document's file type */ 1, /* document icon's local ID */ "" /* associated file (none) */ }; If you're using ResEdit to create the resources, you can just create new resources of the appropriate types and IDs and fill in the blanks with the values above, and then edit the icons graphically. Once you've got all the resources built, you need to do one more thing to let the Finder know that there are icons to be found in the application file. You need to set the bundle bit in the application's file attributes. From MPW, you can do this with SetFile "app's name" -a B , and from ResEdit you can click on the bundle checkbox in the file's Get Info window. You may find that the application's icon still doesn't show up in the Finder. The fast way to fix this is to make sure that whatever window the application's icon shows up in is closed, then jump into ResEdit, do a Get Info on the file, and make sure the bundle checkbox is checked and the inited checkbox isn't. Then quit back to the Finder, open the window with the application, and its icon should show up. Creating data files with the appropriate icon then becomes the simple matter of doing: PBHDelete() /* to get rid of an existing file */ PBHCreate() /* to create a new file */ PBHGetFInfo() /* to get the current file info */ set the type to (for example) 'ADOC' and creator to 'MYAP' in the parameter block PBHSetFInfo() /* to update the type and creator */ PBHOpen() write, write write PBHClose() and that's it... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen | Apple Computer, Inc. | Disclaimer: | 20525 Mariani Ave, MS-81CS | the above may be stevec@apple.com | Cupertino, CA 95014 | a lie...or not.