On Tue, Jan 25, 2011 at 2:48 AM, David Remacle <lis...@clampin.com> wrote:

> Hello
>
> Is it possible to use NSWindow without NIB file ?
>
>
Below is a code sample I put together when I was trying to accomplish the
same thing.  I was pretty against Interface Builder when I first started
with Cocoa because it felt a bit too magical.  Since then I have seen the
light, as they say.  Anyway, here it is, name it WindowNoIB.m:

// Compile and run with:
// $ gcc WindowNoIB.m -Wall -lobjc -framework Foundation -framework AppKit
-o WindowNoIB && ./WindowNoIB
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

// MyClass is going to be the NSApplicationDelegate.  See this:
//
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/Reference/Reference.html
@interface MyClass:NSObject{
}
@property (nonatomic, retain) NSWindow *window;
@end

@implementation MyClass
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
  NSLog(@"Finished Launching %@", notification);

  NSWindow *localWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen
mainScreen] frame]

 styleMask:NSResizableWindowMask

 backing:NSBackingStoreBuffered
                                                          defer:NO];
  [self setWindow:localWindow];
  [localWindow release];

  NSView *localView = [[NSView alloc] init];
  [window setContentView:localView];
  [localView release];

  [window setLevel:NSFloatingWindowLevel];
  [window makeKeyAndOrderFront:self];
}
@end

int main (int argc, const char *argv[]) {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  // The first time sharedApplication is called, it creates an instance of
NSApplication
  //
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html
  [NSApplication sharedApplication];

  NSLog(@"%@", NSApp);

  MyClass *myClass = [[MyClass alloc] init];
  [NSApp setDelegate:myClass];
  [NSApp run];

  [myClass release];
  [pool release];

  return (0);
}

Best,
Lou
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to