ftp.nice.ch/peanuts/GeneralData/Documents/books/AlexNeXTSTEPSource.tar.gz#/NSProgramming/Chapter6_Events/ControlDemo/Control_1.m

This is Control_1.m in view mode; [Download] [Up]

#import <appkit/appkit.h>

// a minimal program to demonstrate how
// to add controls to a window

main()
{
	// create an application object
	// to establish connection to
	// Window Server
	id NXApp = [Application new];
	id theWindow;
	id theMenu;
	id theButton;
	NXRect theRect;

	// create a window that's at 125, 125
	// and is 200 by 300 pixels
	NXSetRect(&theRect, 125, 125, 200, 300);
	theWindow = [ [Window alloc]
		initContent:&theRect
		style: NX_TITLEDSTYLE
		backing:NX_BUFFERED
		buttonMask:NX_MINIATURIZEBUTTONMASK
		defer:YES];

	// create the menu
	theMenu = [ [Menu alloc]
		initTitle: [NXApp appName] ];
	// create the menu option
	[theMenu addItem:"Quit"
		action:@selector(terminate:)
		keyEquivalent:'q'];

	// resize menu to accomodate menu option
	[theMenu sizeToFit];
	[NXApp setMainMenu:theMenu];

	// create a button that's 80 by 20
	NXSetRect(&theRect, 0, 0, 80, 20);
	theButton = [ [Button alloc]
		initFrame:&theRect];
	// set the title for the button
	[theButton setTitle:"Press Here"];
	// since the button is a view, we need
	// to install it as the subview of the
	// window's contentview or else it
	// won't draw
	[ [theWindow contentView]
		addSubview: theButton];

	// send the window to the front
	// and display it
	[theWindow makeKeyAndOrderFront:nil];

	// go into event loop to wait for events
	[NXApp run];
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.