Skip to content

Instantly share code, notes, and snippets.

@aktau
Created January 14, 2014 23:00
Show Gist options
  • Save aktau/8427634 to your computer and use it in GitHub Desktop.
Save aktau/8427634 to your computer and use it in GitHub Desktop.
nibless window creation in cocoa/objc
#import <AppKit/AppKit.h>
// clang -o nibless nibless.m -framework AppKit
@interface TestView : NSView <NSWindowDelegate> { }
-(void)drawRect:(NSRect)rect;
@end
@implementation TestView
-(void)drawRect:(NSRect)rect {
[[NSColor blueColor] set];
NSRectFill( [self bounds] );
}
-(void)windowWillClose:(NSNotification *)note {
[[NSApplication sharedApplication] terminate:self];
}
@end
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSApplication *app = [NSApplication sharedApplication];
NSRect frame = NSMakeRect( 100., 100., 300., 300. );
NSWindow *window = [[NSWindow alloc]
initWithContentRect:frame
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
defer:false];
[window setTitle:@"Testing"];
TestView *view = [[[TestView alloc] initWithFrame:frame] autorelease];
[window setContentView:view];
[window setDelegate:view];
[window makeKeyAndOrderFront:nil];
/* someone mentioned:
* [NSApp activateIgnoringOtherApps:YES];
* not sure where to put it... */
[app run];
[pool release];
return( EXIT_SUCCESS );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment