3

Is there a way to create a NSWindow into fullscreen mode? NSWindow has the ToggleFullscreen: selector but then it creates the window normally and animates it to the fullscreen version which isn't what I want. Any other way of doing it?

AndyTang
  • 547
  • 7
  • 24

2 Answers2

4

First find the screen size

    NSRect screenRect;
    NSArray *screenArray = [NSScreen screens];
    unsigned screenCount = [screenArray count];
    unsigned index  = 0;

    for (index; index < screenCount; index++)
    {
        NSScreen *screen = [screenArray objectAtIndex: index];
        screenRect = [screen visibleFrame];
    }

screenRect contain Screen size, now creat a window and set NSWindow size to screen size.

unsigned int styleMask = NSTitledWindowMask 
                           | NSMiniaturizableWindowMask;


  myWindow = [NSWindow alloc];
  myWindow = [myWindow initWithContentRect: screenRect
                       styleMask: styleMask
                       backing: NSBackingStoreBuffered
                       defer: NO];
  [myWindow setTitle: @"This is a test window"];
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • Doesn't this just maximised the window, not put it into Fullscreen mode? – AndyTang Dec 01 '11 at 09:40
  • Refer http://cocoadevcentral.com/articles/000028.php and http://stackoverflow.com/questions/401240/display-os-x-window-full-screen-on-secondary-monitor-using-cocoa – Parag Bafna Dec 06 '11 at 05:03
3
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    NSRect frame=[NSScreen mainScreen].frame ;
    [self.window setFrame:frame display:YES animate:YES];
}

this will open window in full screen

kleopatra
  • 51,061
  • 28
  • 99
  • 211