tags:

views:

23

answers:

1
A: 

You probably want to handle kEventClassCommand/kEventProcessCommand, and use the command id from the menu item.

HICommand           command;

GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL,
            sizeof( HICommand ), NULL, &command );

switch (command.commandID) {
    case 1:
      ... etc ...

Note that the commandID is one of the parameters to AppendMenuItemTextWithCFString; that's how you can give each item a unique commandID as you generate the menu. commandID's are conventionally 4-char codes (like 'open' or 'save'), but there's no reason you couldn't use simple ints for your dynamically-generated commands.

David Gelhar
Thanks, but this what i'd like to avoid (generating a 4-char code), i really need an index.
Ziggy
You're missing the point: the commandID is simply a 32-bit int (UInt32). While it's conventional to use meaningful 4-char codes for menu items created using interface builder, there's no reason you can't use sequential integers if that's what works best for you.
David Gelhar
How ok, thanks for the advice, sound better like this :)
Ziggy