NSWindowをフルスクリーンで表示 2011/01/12

osxです。「NSWindowをフルスクリーンで表示したい」です。xibを使わないで試してます。

参考


画面のサイズは、NSScreenのmainScreenで取得できます。

参考

試したコード。
アプリケーションを終了するコードは含んでないので、
実行すると画面がまっくろくろすけになるので、command+tabでファインダーを選んでアプリケーションを終了させてください。



#import <Cocoa/Cocoa.h>
#import "mac_app_test_01AppDelegate.h"

int main(int argc, char *argv[])
{
NSLog(@"** a1[%d]", argc);
NSLog(@"** a1[%d]", sizeof(argv));
for (int i=0; i < sizeof(argv); i++) {
NSLog(@"** a1[%s]", argv[i]);
}

id app = [NSApplication sharedApplication];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
mac_app_test_01AppDelegate *a = [mac_app_test_01AppDelegate alloc];
[a autorelease];
[app setDelegate:a];
[app run];
return 0;

// return NSApplicationMain(argc, (const char **) argv);
}

#import

@interface mac_app_test_01AppDelegate : NSObject {
NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;

@end



#import "mac_app_test_01AppDelegate.h"

@implementation mac_app_test_01AppDelegate

@synthesize window;

- (void)go{
/*
* このコードは、
* http://storklab.cyber-ninja.jp/lab/tips/programming/cocoa_fullscreen.html
* を参考にしています。
*/


NSRect mainScreen = [[NSScreen mainScreen] frame];


window = [[NSWindow alloc] initWithContentRect:mainScreen
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];


// 背景を黒に
[window setBackgroundColor:[NSColor blackColor]];

// デアクティブのときは画面を表示しない
[window setHidesOnDeactivate:YES];

// アプリケーションがアクティブでなくてもウインドウを前面に持ってくるらしい
[window orderFrontRegardless];

// メニューバーを消す
[NSMenu setMenuBarVisible:NO];


}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSLog(@"OK\n");
[self go];
}

@end

: