У меня есть следующий код, который в основном работает, за исключением того, что я никогда не вижу myWindow
, который я создаю. Если я делаю [myWindow isVisible]
, он возвращает 1
. CGDisplayCapture
работает нормально, так как гасит экран. Я проверил все переменные, которые я передаю в метод инициализации NSWindow.
Я упускаю что-то действительно очевидное? Вот код:
// 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:NSBackingStoreBuffered
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];
Ваше здоровье