This is Control_3.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; id theSlider; id theTextField; 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]; // create a horizontal slider 100 x 15 NXSetRect(&theRect, 0, 100, 100, 15); theSlider = [ [Slider alloc] initFrame:&theRect]; // set the min value to 0.0 [theSlider setMinValue:0.0]; // set the max value to 10.0 [theSlider setMaxValue:10.0]; [ [theWindow contentView] addSubview:theSlider]; // create a textfield that's 75 by 20 NXSetRect(&theRect, 0, 150, 75, 20); theTextField = [ [TextField alloc] initFrame:&theRect]; // make the text editable [theTextField setEditable:YES]; [ [theWindow contentView] addSubview:theTextField]; // 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.