Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!rutgers!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Help!! ?Changed Menu Made Permanent? Keywords: Menu Resource Message-ID: <23320@apple.Apple.COM> Date: 4 Jan 89 18:45:50 GMT References: <1115@ccnysci.UUCP> Distribution: comp.sys.mac.programmer Organization: Advanced Technology Group, Apple Computer Lines: 38 In article <1115@ccnysci.UUCP> cpyang@ccnysci.UUCP (Chao Ping Yang) writes: >I need to make changes in the Menus of my program and >I want to keep the changes the next time I run the The problem is that when you read in a menu, the data is changed. Specifically, the field of the menu that contains the menu proc ID is replaced with a handle to the menu defproc. When you rewrite the menu resource (with your changes) you write out the version that has the defproc installed, and not the defproc ID. One solution would be to store the menu item strings in a different resource, and reconstruct the menu each time. Then you only have to change the resource containing the items. The problem with this is that it takes more work, and people who want to use ResEdit can't easily customize the menus. A better solution would be to call DetachResource on each of your menus after they have been read in. This dissociates them from the resource file. Then you can change the original version of the MENU resource without affecting the in memory copy (and vice versa). One way to make the change is to call GetResource to read the original MENU resource, and save the defproc ID. Then get the equivalent in memory handle, and copy the data into the resource, and replace the defproc ID with its original value. Then you can call ChangedResource and write the MENU resource back out. A more efficient solution would be to change the defproc handle back to its ID, before doing the ChangedResource. This would eliminate the need to re-read the resource from disk. You have to be careful about restoring the handle, before trying to use the menu again. Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 46-B Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr