[comp.sys.mac.programmer] A Menu Question

donnald@visual1.jhuapl.edu (Creig Donnald) (05/17/91)

I am trying to learn how to program a Mac IIfx using Think C.  I am
running under System 6.0.7.  I have the first two volumes of Inside Macintosh
but not the later ones.

My problem is this:  I use the GetMenu procedure to request menu resources
from my resource file.  However, the MenuID of the requested menus is being
set to 128 rather than the number I supply.  For some reason, this also means
that the menus will not show up on my menubar.

The following segements of code are extracted from my program.  When I 
run it, I get the Apple and File menus but none of the others. 

#define APPLE_MENU_ID        400
#define FILE_MENU_ID         401
#define EDIT_MENU_ID         402
#define FONT_MENU_ID         403
#define STYLE_MENU_ID        404

 . . .

MenuBarInit()
{
  int		i;
  
  myMenus[0] = NewMenu( APPLE_MENU_ID, "\p\024" );
  AddResMenu( myMenus[0], 'DRVR' );
  myMenus[1] = GetMenu (FILE_MENU_ID);
  myMenus[2] = GetMenu (EDIT_MENU_ID);
  myMenus[3] = GetMenu (FONT_MENU_ID);
  myMenus[4] = GetMenu (STYLE_MENU_ID);
  AddResMenu (myMenus[3], 'FONT');
 
  for (i = 0; i <= 4; i++)
    InsertMenu (myMenus[i], 0);

  DrawMenuBar ();
}
  

    The debugger tells me that the menuID for the Apple menu is indeed 400.  
However, all of the other menuIDs are 128, and only the first one shows up.
Can anyone tell me what is going on?  Please email responses to
donnald@visual1.jhuapl.edu.

Thank You

--

sdd@oceania.UUCP (Steve Dakin) (05/18/91)

In article <1991May16.175749.14987@aplcen.apl.jhu.edu>  
donnald@visual1.jhuapl.edu (Creig Donnald) writes:
> I am trying to learn how to program a Mac IIfx using Think C.  I am
> running under System 6.0.7.  I have the first two volumes of Inside Macintosh
> but not the later ones.
> 
> My problem is this:  I use the GetMenu procedure to request menu resources
> from my resource file.  However, the MenuID of the requested menus is being
> set to 128 rather than the number I supply.  For some reason, this also means
> that the menus will not show up on my menubar.
> 

I just ran across this exact same problem about a week ago when I transferred  
all my hard coded menu setup stuff to resources with ResEdit.  The problem, as  
I found it (I would assume that yours is identical) is you have to set the menu  
ID in ADDITION to the resource ID of the MENU.  I can't remember the exact  
command name in the ResEdit menu, but when you edit MENUs with ResEdit 2.1,  
there is a new menu that gets added to the ResEdit menubar that is specific to  
editing MENU resources.  The first item in that menu is what allows you set the  
menu ID.  It is this menu ID that needs to be unique for your menus to appear.   
If this is too confusing, email me and I will give ya more details later after  
I poke around with ResEdit.

--
+-----------------------------------+
|            Steve Dakin            |
|     oceania!sdd@uunet.uu.net      |
|            (NeXT mail)            |
| tread lighty so others may follow |
+-----------------------------------+

-- 
+-----------------------------------+
|            Steve Dakin            |
|     oceania!sdd@uunet.uu.net      |
|            (NeXT mail)            |

Jim.Spencer@p510.f22.n282.z1.fidonet.org (Jim Spencer) (05/21/91)

Creig Donnald writes in a message to All

CD> My problem is this: I use the GetMenu procedure to request menu 
CD> resources from my resource file. However, the MenuID of the requested 
CD> menus is being set to 128 rather than the number I supply. For 
CD> some reason, this also means that the menus will not show up 
CD> on my menubar. 

Every menu has a menu ID regardless of whether it is created by you in your program with NewMenu() or by a resource with GetMenu.  When you use NewMenu() like in your Apple menu, you provide the menuID.  When you build your menu from a resource, the resource contains the ID.  Menu resources however also, like all resources have a resource ID which is not necessarily the same as the menuID for the menu in the resource.

When you create your menus in ResEdit, it initially sets both ID's to the same number, 128 or the next highest unused ID.  You apparently have changed the resource IDs to your own number, 401 - 404 but you have not changed the menu ID's to match.  Its been a while since I've looked at what happens when you have menuID conflicts but I think the reason that the File menu is showing up is that it is the first with menuID = 128.  The others don't get added as there already is a menuID 128 in the menuBar.

I assume you know how to change the menu resource ID but just to be sure there is no confusion, the resource ID is set in ResEdit just like any other resource: by selecting Get Resource Info from the Resource menu when you have selected a specific MENU resource in the picker or the editor.  The menuID is set by selecting Edit Menu & MDEF ID... under the Menu menu when you have a particular menu resource open in the editor.
 
 * Origin: White Mailer Test Point (1.0d6) (1:282/22.510)