Created
January 14, 2014 23:00
-
-
Save aktau/8427634 to your computer and use it in GitHub Desktop.
nibless window creation in cocoa/objc
This file contains 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 <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