yoga1290

NSWindow Test

May 15th, 2011
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.m
  3. //  hello
  4. //
  5. //  Created by Youssef Gamil on ٢٩‏/٤‏/٢٠١١.
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import <Cocoa/Cocoa.h>
  10. #include <AppKit/AppKit.h>
  11. #import <Foundation/Foundation.h>
  12. @interface MyDelegate : NSObject {
  13.     NSWindow *myWindow;
  14. }
  15. - (void) createMenu;
  16. - (void) createWindow;
  17. - (void) applicationWillFinishLaunching: (NSNotification *)not;
  18. - (void) applicationDidFinishLaunching: (NSNotification *)not;
  19. @end
  20.  
  21. @implementation MyDelegate : NSObject
  22.  
  23. - (void) dealloc {
  24. //  RELEASE (myWindow);
  25.     [myWindow dealloc];
  26. }
  27.  
  28. - (void) createMenu {
  29.     NSMenu *menu;
  30.     menu=[NSMenu alloc];
  31. //  menu = AUTORELEASE ([NSMenu new]);
  32.     [menu addItemWithTitle: @"Quit" action: @selector (terminate:) keyEquivalent: @"q"];
  33.     [NSApp setMainMenu: menu];
  34. }
  35.  
  36. - (void) createWindow {
  37.     NSRect rect = NSMakeRect (100, 100, 200, 200);
  38.     unsigned int styleMask = NSTitledWindowMask | NSMiniaturizableWindowMask;
  39.     myWindow=[NSWindow alloc];
  40.     myWindow = [myWindow initWithContentRect:rect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
  41.    
  42.     [myWindow setTitle: @"This is a test window"];
  43. }
  44.    
  45. - (void) applicationWillFinishLaunching: (NSNotification *)not {
  46.     [self createMenu];
  47.     [self createWindow];
  48. }
  49.  
  50. - (void) applicationDidFinishLaunching: (NSNotification *)not;
  51. {
  52.     [myWindow makeKeyAndOrderFront: nil];
  53. }
  54. @end
  55.    
  56. int main(int argc, char *argv[])
  57. {
  58.     NSRect rect = NSMakeRect (100, 100, 200, 200);
  59.     unsigned int styleMask = NSTitledWindowMask | NSMiniaturizableWindowMask;
  60.     NSWindow *myWindow;
  61.     myWindow=[NSWindow alloc];
  62.     myWindow = [myWindow initWithContentRect:rect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
  63.    
  64.     [myWindow setTitle: @"This is a test window"];
  65.    
  66.     [NSApp setDelegate: [MyDelegate new]];
  67.     return NSApplicationMain(argc,  (const char **) argv);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment