Created
October 16, 2011 17:38
-
-
Save inky/1291177 to your computer and use it in GitHub Desktop.
Tiny OS X app based on http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Cocoa/Cocoa.h> | |
| #import <AppKit/AppKit.h> | |
| #define NEW(a) [[a new] autorelease] | |
| @interface Maign : NSObject | |
| - (void)buttonAction:(id)sender; | |
| @end | |
| @implementation Maign | |
| - (void)buttonAction:(id)sender | |
| { | |
| id alert = [[[NSAlert alloc] init] autorelease]; | |
| [alert setMessageText:@"I DIIIIID IT"]; | |
| [alert addButtonWithTitle:@"OK"]; | |
| [alert runModal]; | |
| } | |
| @end | |
| int main() | |
| { | |
| [NSAutoreleasePool new]; | |
| [NSApplication sharedApplication]; | |
| [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
| id menubar = [[NSMenu new] autorelease]; | |
| id appMenuItem = [[NSMenuItem new] autorelease]; | |
| [menubar addItem:appMenuItem]; | |
| [NSApp setMainMenu:menubar]; | |
| id appMenu = [[NSMenu new] autorelease]; | |
| id appName = [[NSProcessInfo processInfo] processName]; | |
| id quitTitle = [@"Quit " stringByAppendingString:appName]; | |
| id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle | |
| action:@selector(terminate:) | |
| keyEquivalent:@"q"] autorelease]; | |
| [appMenu addItem:quitMenuItem]; | |
| [appMenuItem setSubmenu:appMenu]; | |
| id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) | |
| styleMask:NSTitledWindowMask | |
| backing:NSBackingStoreBuffered | |
| defer:NO] autorelease]; | |
| [window cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; | |
| [window setTitle:appName]; | |
| [window setBackgroundColor:[NSColor yellowColor]]; | |
| id button = [[[NSButton alloc] initWithFrame:NSMakeRect(50, 50, 100, 30)] autorelease]; | |
| [button setTitle:@":¬)"]; | |
| [button setAction:@selector(buttonAction:)]; | |
| [button setTarget:[[[Maign alloc] init] autorelease]]; | |
| [[window contentView] addSubview:button]; | |
| [window makeKeyAndOrderFront:nil]; | |
| [NSApp activateIgnoringOtherApps:YES]; | |
| [NSApp run]; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| APP = Tiny App | |
| APP_DIR = $(APP).app | |
| BIN_DIR = $(APP_DIR)/Contents/MacOS | |
| FRAMEWORKS = -framework Cocoa -framework AppKit | |
| app: | |
| mkdir -p "$(BIN_DIR)" | |
| gcc $(FRAMEWORKS) -x objective-c -o "$(BIN_DIR)/$(APP)" main.m | |
| clean: | |
| rm -rf "$(APP_DIR)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment