You need to log in to create posts and topics.
Tutorial_7
1,678 Posts
#1 · September 17, 2011, 10:41 am
Quote from Forum Archives on September 17, 2011, 10:41 amPosted by: svanvoorst <svanvoorst@...>
/*Demonstrates construction of an About Panel.S. Van Voorst {20110917}References:1) NSApplication Class Reference2) Technical Note TN2179*/compile as "Objective-C"if system(_sysVers) < 1060 then stop "Requires OS 10.6 or newer"include resources "myImage.png"BeginCDeclaration@interface AppController : NSObject{}- (void) aboutHandler:(id)sender;@end //interfaceEndCBeginCFunction@implementation AppController- (void) aboutHandler:(id)sender{NSDictionary *options;NSImage *image;image = [NSImage imageNamed: @"myImage.png"];options = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"Version",@"Super App", @"ApplicationName",image, @"ApplicationIcon",@"Copyright 2011, MyGreatCompany", @"Copyright",@"Super App v1.1", @"ApplicationVersion",nil];[[NSApplication sharedApplication] orderFrontStandardAboutPanelWithOptions:options];}@end //implementationEndCBeginCCode{NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];[NSApplication sharedApplication];[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];// --- Create an instance of the controller class --- //id myController = [[AppController alloc]init];// ******** Menu and menubar ********//id menubar = [[NSMenu new] autorelease];id appMenuItem = [[NSMenuItem new] autorelease];[menubar addItem:appMenuItem];[NSApp setMainMenu:menubar];id appMenu = [[NSMenu new] autorelease];// ***** About MenuItem ******//id appName = [[NSProcessInfo processInfo] processName];id aboutTitle = [@"About " stringByAppendingString:appName];id aboutMenuItem = [[[NSMenuItem alloc]initWithTitle:aboutTitleaction:@selector(aboutHandler:) keyEquivalent:@""] autorelease];[appMenu addItem:aboutMenuItem];[aboutMenuItem setTarget:myController];[appMenu addItem:[NSMenuItem separatorItem]];// ***** Quit MenuItem ****** //// id appMenu = [[NSMenu new] autorelease];id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"action:@selector(terminate:) keyEquivalent:@"q"] autorelease];[appMenu addItem:quitMenuItem];[appMenuItem setSubmenu:appMenu];// ******** Window ******** //#define _wndW 300#define _wndH 250id window = [[NSWindow alloc] initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )styleMask:NSTitledWindowMask | NSClosableWindowMaskbacking:NSBackingStoreBuffereddefer:NO];[window center];[window setTitle:@"About Panel_demo"];[window makeKeyAndOrderFront:nil];// ***** Quit btn ***** //NSButton *quitBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 130, 30, 95, 30 )];[quitBtn setBezelStyle:NSRoundedBezelStyle ];[quitBtn setTitle: @"Quit" ];[quitBtn setAction:@selector(terminate:)];[[window contentView] addSubview: quitBtn];[quitBtn release];[NSApp activateIgnoringOtherApps:YES];[NSApp run];[myController release];[pool drain];}EndC
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Posted by: svanvoorst <svanvoorst@...>
/*
Demonstrates construction of an About Panel.
S. Van Voorst {20110917}
References:
1) NSApplication Class Reference
2) Technical Note TN2179
*/
compile as "Objective-C"
if system(_sysVers) < 1060 then stop "Requires OS 10.6 or newer"
include resources "myImage.png"
BeginCDeclaration
@interface AppController : NSObject
{
}
- (void) aboutHandler:(id)sender;
@end //interface
EndC
BeginCFunction
@implementation AppController
- (void) aboutHandler:(id)sender
{
NSDictionary *options;
NSImage *image;
image = [NSImage imageNamed: @"myImage.png"];
options = [NSDictionary dictionaryWithObjectsAndKeys:
@"1", @"Version",
@"Super App", @"ApplicationName",
image, @"ApplicationIcon",
@"Copyright 2011, MyGreatCompany", @"Copyright",
@"Super App v1.1", @"ApplicationVersion",
nil];
[[NSApplication sharedApplication] orderFrontStandardAboutPanelWithOptions:options];
}
@end //implementation
EndC
BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
// --- Create an instance of the controller class --- //
id myController = [[AppController alloc]init];
// ******** Menu and menubar ********//
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
// ***** About MenuItem ******//
id appName = [[NSProcessInfo processInfo] processName];
id aboutTitle = [@"About " stringByAppendingString:appName];
id aboutMenuItem = [[[NSMenuItem alloc]initWithTitle:aboutTitle
action:@selector(aboutHandler:) keyEquivalent:@""] autorelease];
[appMenu addItem:aboutMenuItem];
[aboutMenuItem setTarget:myController];
[appMenu addItem:[NSMenuItem separatorItem]];
// ***** Quit MenuItem ****** //
// id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
// ******** Window ******** //
#define _wndW 300
#define _wndH 250
id window = [[NSWindow alloc] initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask:NSTitledWindowMask | NSClosableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle:@"About Panel_demo"];
[window makeKeyAndOrderFront:nil];
// ***** Quit btn ***** //
NSButton *quitBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 130, 30, 95, 30 )];
[quitBtn setBezelStyle:NSRoundedBezelStyle ];
[quitBtn setTitle: @"Quit" ];
[quitBtn setAction:@selector(terminate:)];
[[window contentView] addSubview: quitBtn];
[quitBtn release];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[myController release];
[pool drain];
}
EndC
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Click for thumbs down.0Click for thumbs up.0