Re: Initializing the menubar
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