• 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
Re: Initializing the menubar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing the menubar


  • Subject: Re: Initializing the menubar
  • From: Robert Nikander <email@hidden>
  • Date: Sat, 3 Nov 2007 20:15:43 -0400

Okay... I've got a menu to show up, but the behavior seems to depend on the location of the executable file, which I don't understand.

If I put the code below in a file called "cocoa.m" and compile it from the command line with:

   gcc -o cocoa cocoa.m -framework Cocoa

and I run it like this:

   ./cocoa

then no menu shows up. But if I copy the binary into a bundle directory, like this:

   cp cocoa CocoaTest.app/Contents/MacOS/CocoaTest

and run that same binary, at the different location:

   ./CocoaTest.app/Contents/MacOS/CocoaTest

then the menu bar shows up.

Why the difference? Does a cocoa binary have to run from within a bundle directory?

thanks,
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];


NSMenu *mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
NSMenuItem *mi;
NSMenu *m;
mi = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""];
m = [[NSMenu alloc] initWithTitle:@"Apple"];
// strange hack
[NSApp performSelector:@selector(setAppleMenu:) withObject: m];
[mainMenu setSubmenu:m forItem:mi];
mi = [m addItemWithTitle: @"Test Item"
action: nil
keyEquivalent: @""];


    [app setMainMenu: mainMenu];

    [window makeKeyAndOrderFront: window];

    [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
      • From: Eric Schlegel <email@hidden>
References: 
 >Initializing the menubar without Interface Builder (From: Robert Nikander <email@hidden>)
 >Re: Initializing the menubar without Interface Builder (From: mmalc crawford <email@hidden>)
 >Re: Initializing the menubar without Interface Builder (From: Robert Nikander <email@hidden>)
 >Re: Initializing the menubar without Interface Builder (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: [Moderator] Please take this to another forum - Re: Adding an icon to the dock
  • Next by Date: re: Enumerating over managed object to-many relationships
  • Previous by thread: Re: Initializing the menubar without Interface Builder
  • Next by thread: Re: Initializing the menubar
  • Index(es):
    • Date
    • Thread