[comp.sys.mac.programmer] Add1ResMenu routine needed

tj@cs.ucla.edu (Tom Johnson) (07/13/90)

Does anyone know how I can force AddResMenu to add resources only from the
current res file?  The standard call add resources from all open files--
I want to be able to limit it to just those in my INIT (I don't want every
font there is added to my menu, just the ones in my INIT file).  I guess
I'm just being lazy--I don't want to re-invent the wheel;

Thanks-
  Tom
--
Tom Johnson      UCLA Computer Science Department 
			3413 Boelter Hall, Los Angeles CA 90024 (213)825-6952
			Internet:  tj@cs.ucla.edu

mxmora@unix.SRI.COM (Matt Mora) (07/13/90)

In article <36918@shemp.CS.UCLA.EDU> tj@cs.ucla.edu (Tom Johnson) writes:
>Does anyone know how I can force AddResMenu to add resources only from the
>current res file?  The standard call add resources from all open files--
>I want to be able to limit it to just those in my INIT (I don't want every
>font there is added to my menu, just the ones in my INIT file).  I guess
>I'm just being lazy--I don't want to re-invent the wheel;
>
>Thanks-
>--
>Tom Johnson      UCLA Computer Science Department 


I had to write my own addresmenu because Addresmenu sorts the resource names.
Its trivial to implement. Below is some code in pascal.

	FieldMenu := GetMenu(FieldMenuID)
	gNumFields := CountResources('FLDS');
  	for i := 1 to gNumFields do
		begin
			tempH := Get1Resource('FLDS', i);
			GetResInfo(tempH, id, rType, name);
			fieldsSTR[i] := name;
			AppendMenu(FieldMenu, name);
			DetachResource(tempH);
			FieldStr[i] := tempH;
		end;


You just need the code up to the Appendmenu part. I needed to used the 
handles later in my program. This of course is an unsorted list.



-- 
___________________________________________________________
Matthew Mora                |   my Mac  Matt_Mora@sri.com
SRI International           |  my unix  mxmora@unix.sri.com
___________________________________________________________

han@apple.COM (Byron Han, Project Scapegoat) (07/17/90)

In article <14104@unix.SRI.COM> mxmora@unix.SRI.COM (Matt Mora) writes:
>         FieldMenu := GetMenu(FieldMenuID)
>         gNumFields := CountResources('FLDS');
>         for i := 1 to gNumFields do
>                 begin
>                         tempH := Get1Resource('FLDS', i);
>                         GetResInfo(tempH, id, rType, name);
>                         fieldsSTR[i] := name;
>                         AppendMenu(FieldMenu, name);
>                         DetachResource(tempH);
>                         FieldStr[i] := tempH;
>                 end;

You will probably want to bracket the calls to Get1Resource() with 
SetResLoad(FALSE)/SetResLoad(TRUE) to cut down on memory usage.

You also should check to see if the resource returned from Get1Resource() 
is NIL or not.

Another problem is that if the resource name contains any of the special 
Menu Manager metacharacters, the menu may look funny.

I often use,
     AppendMenu(hMenu, 'X');
     curItem := CountMItems(hMenu);
     SetItem(hMenu, curItem, theRealThing);

Hope this helps!

+-------------------------------------------------------------------------+
| Disclaimer: Apple has no connection with my postings.                   |
+-------------------------------------------------------------------------+
Byron Han, CommToolbox Scapegoat  "Not Working 100 hrs/wk and loving it!"
Apple Computer, Inc.              --------------------------------
20525 Mariani Ave, MS 69L         Internet: han@apple.COM
Cupertino, CA 95014               UUCP:{sun,voder,nsc,decwrl}!apple!han
--------------------------------  GENIE:BYRONHAN   CompuServe:72167,1664
ATTnet: 408-974-6450              Applelink:HAN1   HAN1@applelink.apple.COM
---------------------------------------------------------------------------