Re: Programmatically creating the Application Menu
Re: Programmatically creating the Application Menu
- Subject: Re: Programmatically creating the Application Menu
- From: Jonathan Johnson <email@hidden>
- Date: Thu, 8 Dec 2005 14:56:14 -0600
On 12/8/05, Jonathan Johnson <email@hidden> wrote:
>
Part curiosity, part usefulness, how does one create the application
>
menu via code? [NSApplication setMainMenu:] seems to not touch the
>
application menu, and it remains blank. How do you add items to the
>
application menu (assuming no nib file)? Is there a way to create the
>
standard set of items for the application menu?
I'll elaborate. If I don't call [NSApplication setMainMenu:], there is
one top-level menu automatically created for me (the application
menu). It will have Services, the Hide pair, and Quit. However, when I
use the code below the application menu is cleared. I can't seem to
find out how to get a handle to the application menu to actually add
items back to it.
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApplication *app = [NSApplication sharedApplication];
// Create the main menu that will house each real menu
// File, Edit, etc.
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
[app setMainMenu:menu];
// Create the file menu.
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"" action:nil
keyEquivalent:@""] autorelease];
[item setSubmenu:[[[NSMenu alloc] initWithTitle:@"File"] autorelease]];
[menu addItem:item];
// Run the app
[app run];
return 0;
}
Any help is appreciated.
Thanks,
Jon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden