NSHUDWindowMaskなNSPanelを生成する方法
Interface Builderを使わずにWindowを表示する一例(?)
僕は本格的にCocoaを触り始めて一週間弱のビギナーですので、予めそのことをご了承ください。
ポイント
styleMaskの "NSHUDWindowMask" は NSWindow には設定出来ないので、NSPanelを継承したクラスを作る(この例では hudWindow)
(NSPanel及びNSHUDWindowMaskについてはこちらを参照:http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPanel_Class/Reference/Reference.html)
TestAppDelegate.h
#import <Cocoa/Cocoa.h> @interface TestAppDelegate : NSObject <NSApplicationDelegate> { NSPanel *hudWindow; NSButton *hudButton; NSTextField *hudTextField; } @property (assign) IBOutlet NSWindow *window; - (void)processAction:(id)sender; @end
TestAppDelegate.m
#import "TestAppDelegate.h" @implementation TestAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSScreen *mainScreen = [NSScreen mainScreen]; hudWindow = [[NSPanel alloc] initWithContentRect:NSMakeRect(100, 100, 300, 44) styleMask:NSResizableWindowMask|NSHUDWindowMask|NSUtilityWindowMask|NSClosableWindowMask backing:NSBackingStoreRetained defer:NO screen:mainScreen]; // ============================================================================= hudTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 180, 24)]; [hudTextField setObjectValue:@"Hello HUDWindow"]; [hudTextField setEditable:YES]; [hudTextField setTarget:self]; [hudTextField setAction:@selector(processAction:)]; [[hudWindow contentView] addSubview:hudTextField]; [hudTextField release]; hudButton = [[NSButton alloc] initWithFrame:NSMakeRect(200, 10, 80, 24)]; [hudButton setTitle:@"Click Me"]; [hudButton setTarget:self]; [hudButton setAction:@selector(processAction:)]; [hudButton setBezelStyle:NSRoundRectBezelStyle]; [[hudWindow contentView] addSubview:hudButton]; [hudButton release]; // ============================================================================= [hudWindow setTitle:@"NSHUDWindow styleMask Test"]; [hudWindow setDisplaysWhenScreenProfileChanges:YES]; [hudWindow makeKeyAndOrderFront:self]; } - (void)processAction:(id)sender { NSLog(@"TestAppDelegate::processAction"); NSLog(@"%@", [hudTextField objectValue]); }