开发者

Cocoa fullscreen window on secondary display

I have the follow code which mostly works apart from I can never see the myWindow that I create. If I do [myWindow isVisible] it returns 1. The CGDisplayCapture works fine as it blanks out the screen. I've checked all the variables I pass into the NSWindow init method.

Am I missing something really obvious? Here's the code:

// Find the screen we want
NSScreen *screen                = [[NSScreen screens] objectAtIndex:1];
NSNumber *displayID             = [[screen deviceDescription] 
                                  objectForKey:@"NSScreenNumber"];
CGDirectDisplayID CGDisplayID   = (CGDirectDisplayID) [displayID intValue];

// Capture the secondary display
if (CGDisplayCapture( CGDisplayID ) != kCGErrorSuccess) {
  NSLog( @"Couldn't capture the secondary display" );
}

// Draw a new window to fill the screen
NSRect screenRect = [screen frame];
NSWindow *myWindow = [[NSWindow alloc] initWithContentRect:screenRect
                                               styleMask:NSBorderlessWindowMask
                                                 backing:NSBackingStoreBuffer开发者_开发百科ed
                                                   defer:NO
                                                  screen:screen];

// Set the level of the new window and other settings
NSInteger windowLevel = CGShieldingWindowLevel();
[myWindow setLevel: windowLevel];
[myWindow setBackgroundColor:[NSColor blueColor]];
[myWindow makeKeyAndOrderFront:nil];

Cheers


If you can require 10.5 or above, please use NSView's -enterFullScreenMode:withOptions: and the matching -exitFullScreenModeWithOptions:. This properly shifts the responsibility to a container view (which can still have its own complex set of subviews) and frees you from some of the gotcha's of manually messing with window levels, etc.


What does this window look like if you don't make it full-screen?

I don't see you adding any views to the window you're creating. If your window's content view is an NSView instance, it's not going to do any drawing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜