greggor@apple.com (Greg L. Anderson) (09/30/90)
I mailed the following information to someone interested in creating custom icons for the Macintosh Application he was writing for a class project. It turned out to be quite long, so I decided I would post it in case other people on the net were interested. Hopefully I'm not just wasting bandwidth... ---- How to create custom icons for your Macintosh Applications and the files that they create: (These instructions assume the use of ResEdit 2.0b2 and THINK C.) 1. From THINK C, go to "Set Project Type" You will see two editable text fields in the upper right hand corner; one is "FILE TYPE" and the other is "FILE CREATOR". "FILE TYPE" should be "APPL" (all uppercase). Change it to this if it isn't. "FILE CREATOR" will probably be "????". You should change this to a (hopefully) unique ID that will identify your program; it must be four characters long, no more, no less. For example, my program "Pon Nuki" has a File Creator of "PNUK". Every file on the Macintosh has a file type and a file creator. Executable files have a file type of 'APPL', while files that contain plain ASCII have a file type of 'TEXT'. Files that have other strange information in them have file types unique to the App that created them. In theory, all file types and file creators that you invent should be registered with Apple to insure that they really are unique. All of my example types have been all uppercase, but lowercase letters are legal too, and distinguishable from uppercase (i.e., 'text' is a different file type than 'TEXT'). All Icons displayed by the finder are a direct function of the file type and file creator of that file. The finder gets the actual bitmap for the Icons from the 'Desktop' file, but that's not where you put them: all of the resources needed to display custom icons belongs in the resource fork of the Application that owns the file. The Finder copies this information to the 'Desktop' file itself. It's usually pretty good about doing this automatically when brand new file type/file creator combinations show up, but if you subsiquently edit the icon bitmaps, you'll find that the icons displayed by the Finder don't change. To fix this problem, simply rebuild the desktop (hold down Command-Shift-Option while rebooting your Macintosh), and the Finder will put the correct icons into the desktop file. 2. When you save files with 'Create' and 'FSOpen', use code that looks like this: (I should mention that using standard C fopen calls is out) Str255 fileName; short vRefNum; FInfo fndrInfo; long fileCreator = 'MYTP'; long fileType = 'TEXT'; OSErr theErr; theErr = Create( fileName, vRefNum, fileCreator, fileType ); if( theErr == dupFNErr ) { theErr = GetFInfo( fileName, vRefNum, &fndrInfo ); theErr = FSDelete( fileName, vRefNum ); theErr = Create(fileName,vRefNum,fileCreator,fileType); fndrInfo.fdType = fileType; theErr = SetFInfo( fileName, vRefNum, &fndrInfo ); } theErr = FSOpen( fileName, vRefNum, &fRefNum ); You can trash the 'if' statement and all of the code inside it if you will never be changing the file type or file creator of an existing file. Usually, you'll never want to make a file with a file creator that is not the file creator of your app, so the question is, why would you want multiple file types, and why might they change on the fly? Pon Nuki uses a different file type based on who's turn is next; a different file type implies a different icon, so the user has a visual indication of who plays next just by looking at the file's icon. If you don't delete and recreate the file, the Finder won't redraw its icon until you close and reopen the window it lives in. The 'GetFInfo' and 'SetFInfo' calls insure that the icons stays in the same place after it is deleted and recreated. Pon Nuki will (someday soon) allow you to play games over the network, so the changing-file-icon feature will be a very useful indication that your opponant has made a move (since you won't necessarily want to keep the game window open at all times). Once you've gotten this far, users will be able to double-click on the documents created by your App, and doing so will launch your App. You don't have custom icons yet, but I think I'll digress for a moment and throw in some more sample code to illustrate how your App can load the files that the user double-clicked on: short message; short preLoadFiles; CountAppFiles( &message, &preLoadFiles ); for(i=1;i<=preLoadFiles;++i) { GetAppFiles(i,&theFile); OpenAFile( theFile.fName, theFile.vRefNum ); } 'message' is zero to load or one to print the files, but I'm too lazy to check for printing. theFile.fName is an Str255, while theFile.vRefNum is a short. These are just like the values returned by SFGetFile. 3. Open 'myProjectName.rsrc' with ResEdit 2.0b2 and create a resource of type 'BNDL'. Do this with the "Create New Resource" (Command-K) option under the "Resource" menu. 4. You will notice that there is an editable text field at the top of the BNDL editor that is marked "Signature". Change this to your _FILE CREATOR_. (This is a very important step.) 5. Create a new file type with the "Create New File Type" (Command-K) option under the "Resource" menu. Yes, this is the same item that used to be "Create New Resource"; this item transmorgifies based on what you're doing. 6. You will get a new line in the BNDL editor that has "????" on the left and a bunch of squares on the right. Click on the "????" and change it to "APPL". 7. Double-click on the first square next to the "APPL". You will get a nice dialog asking you to choose an icon for the file type "APPL". Just click on the button marked "New". 8. You will now be in a very nice Icon editor. You will notice that you can edit many different types of icons with this editor; some are big, some are small, some are color and some are black and white. Only the big, black and white icon (the one marked 'ICN#') and its corresponding mask are used in system 6. System 7 supports color icons, so that's what the other icons are for. I drew nice color icons for Pon Nuki, but System 7 drew the black and white version anyway. :< I was using 7.0a12, so perhaps it works better now, or perhaps I did something wrong, or perhaps I just needed to rebuild the desktop. I'm not sure. At any rate, draw the icon for your Application, make a mask for it and then close the icon editor. 9. Repeat steps 5-8 for every file type that your program creates. Of course, in step 7 you should enter in the appropriate file type rather than "APPL". That's it! Resedit 2.0b2 creates the FREF resource for you, so you're all done. Needless to say, this is MUCH harder to do with ResEdit 1.2. Oh, there is one more optional step you might want to take: 10. Select "Extended view" from the "BNDL" menu (when you're looking at the BNDL editor). A new editable text field labled "Copyright String" will appear. Type text into this field. It will show up in the "Get Info" box of your Application right next to the "Version:" label. ___\ /___ Greg Anderson ___\ /___ \ \ / / Advanced Technology Group \ \ / / \ /\/\ / Apple Computer, Inc. \ /\/\ / \/ \/ greggor@apple.com \/ \/