static void setApplicationMenu(void) { NSMenu *appleMenu, *services; NSMenuItem *menuItem; NSString *title; NSString *appName; appName = @"hello"; appleMenu = [[NSMenu alloc] initWithTitle:@""]; /* Add menu items */ title = [@"About " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; // Services Menu services = [[[NSMenu alloc] init] autorelease]; [appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""]; [appleMenu setSubmenu: services forItem: [appleMenu itemWithTitle: @"Services"]]; // Hide AppName title = [@"Hide " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; // Hide Others menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; // Show All [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; // Quit AppName title = [@"Quit " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [menuItem setSubmenu: appleMenu]; [[NSApp mainMenu] addItem: menuItem]; /* Tell the application object that this is now the application menu */ [NSApp setAppleMenu: appleMenu]; [NSApp setServicesMenu: services]; /* Finally give up our references to the objects */ [appleMenu release]; [menuItem release]; } static int window_create(int width, int height) { NSWindow *window; NSRect contentRect; unsigned int style; contentRect = NSMakeRect(0, 0, width, height); style = NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask | NSResizableWindowMask; window = [[NSWindow alloc] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered defer:NO]; [window center]; [window setViewsNeedDisplay:NO]; [window setTitle:@"Hello"]; [window makeKeyAndOrderFront:nil]; return 1; } int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; [NSApplication sharedApplication]; [NSApp setMainMenu:[[NSMenu alloc] init]]; setApplicationMenu(); window_create(400, 400); [pool release]; [NSApp run]; return 0; }