RosettaCodeData/Task/Window-creation/Objective-C/window-creation.m

50 lines
1,002 B
Mathematica
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
@interface Win : NSWindow
{
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
@end
@implementation Win : NSWindow
2015-02-20 00:35:01 -05:00
-(instancetype) init
2013-04-11 01:07:29 -07:00
{
2014-04-02 16:56:35 +00:00
if ((self = [super
2013-04-11 01:07:29 -07:00
initWithContentRect: NSMakeRect(0, 0, 800, 600)
styleMask: (NSTitledWindowMask | NSClosableWindowMask)
backing: NSBackingStoreBuffered
2014-04-02 16:56:35 +00:00
defer: NO])) {
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
[self setTitle: @"A Window"];
[self center];
}
2013-04-11 01:07:29 -07:00
return self;
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification
{
[self orderFront: self];
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification
{
return YES;
}
@end
int main()
{
2014-04-02 16:56:35 +00:00
@autoreleasepool {
[NSApplication sharedApplication];
Win *mywin = [[Win alloc] init];
[NSApp setDelegate: mywin];
[NSApp runModalForWindow: mywin];
}
2013-04-11 01:07:29 -07:00
return EXIT_SUCCESS;
}