Skip to content

Instantly share code, notes, and snippets.

@inky
Created October 16, 2011 17:38
Show Gist options
  • Select an option

  • Save inky/1291177 to your computer and use it in GitHub Desktop.

Select an option

Save inky/1291177 to your computer and use it in GitHub Desktop.
#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;
}
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