• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Initializing the menubar without Interface Builder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Initializing the menubar without Interface Builder


  • Subject: Initializing the menubar without Interface Builder
  • From: Robert Nikander <email@hidden>
  • Date: Sat, 3 Nov 2007 13:12:03 -0400

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];
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Initializing the menubar without Interface Builder
      • From: mmalc crawford <email@hidden>
    • Re: Initializing the menubar without Interface Builder
      • From: Jeff Johnson <email@hidden>
    • Re: Initializing the menubar without Interface Builder
      • From: Jeff Johnson <email@hidden>
  • Prev by Date: Re: Adding an icon to the dock
  • Next by Date: Re: [WebFrame url] -- How to get the initial URL from WebView or WebFrame?
  • Previous by thread: Re: Quitting when Menu closes
  • Next by thread: Re: Initializing the menubar without Interface Builder
  • Index(es):
    • Date
    • Thread