FROM : Robert Nikander
DATE : Sat Nov 03 18:12:03 2007
Hi all,
How do I setup the menu bar if I'm not using Interface Builder?
Here's some sample code that pops up a window, but there are no menus.
I could answer this myself if I could see the source code for
NSApplicationMain, but that's not available, correct?
thank you,
Rob
#import <Cocoa/Cocoa.h>
int main()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApplication *app = [NSApplication sharedApplication];
id window = [[NSWindow alloc] initWithContentRect: NSMakeRect
(10,10,100,100)
styleMask: NSTitledWindowMask |
NSResizableWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
[window makeKeyAndOrderFront: window];
id m = [[NSMenu alloc] initWithTitle: @"Test Menu"];
id mi = [[NSMenuItem alloc] initWithTitle: @"Test Menu Item"
action: nil
keyEquivalent: @""];
[m addItem: mi];
printf ("mainMenu: %p\n", [app mainMenu]);
[app setMainMenu: m];
[NSMenu setMenuBarVisible: YES];
[app run];
[pool release];
}
DATE : Sat Nov 03 18:12:03 2007
Hi all,
How do I setup the menu bar if I'm not using Interface Builder?
Here's some sample code that pops up a window, but there are no menus.
I could answer this myself if I could see the source code for
NSApplicationMain, but that's not available, correct?
thank you,
Rob
#import <Cocoa/Cocoa.h>
int main()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApplication *app = [NSApplication sharedApplication];
id window = [[NSWindow alloc] initWithContentRect: NSMakeRect
(10,10,100,100)
styleMask: NSTitledWindowMask |
NSResizableWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
[window makeKeyAndOrderFront: window];
id m = [[NSMenu alloc] initWithTitle: @"Test Menu"];
id mi = [[NSMenuItem alloc] initWithTitle: @"Test Menu Item"
action: nil
keyEquivalent: @""];
[m addItem: mi];
printf ("mainMenu: %p\n", [app mainMenu]);
[app setMainMenu: m];
[NSMenu setMenuBarVisible: YES];
[app run];
[pool release];
}
| Related mails | Author | Date |
|---|---|---|
| Robert Nikander | Nov 3, 18:12 | |
| Jeff Johnson | Nov 3, 18:37 | |
| Jeff Johnson | Nov 3, 18:46 | |
| mmalc crawford | Nov 3, 19:29 | |
| Robert Nikander | Nov 3, 19:54 | |
| Robert Nikander | Nov 3, 20:08 | |
| mmalc crawford | Nov 4, 00:13 | |
| Robert Nikander | Nov 4, 01:15 | |
| Eric Schlegel | Nov 4, 17:25 | |
| Robert Nikander | Nov 4, 18:05 |






Cocoa mail archive

