gpt4 book ai didi

辅助显示屏上的 cocoa 全屏窗口

转载 作者:行者123 更新时间:2023-12-03 16:29:48 26 4
gpt4 key购买 nike

我有以下代码,除了我永远看不到我创建的 myWindow 之外,它大部分都可以工作。如果我执行[myWindow isVisible],它会返回1。 CGDisplayCapture 工作正常,因为它会清空屏幕。我已经检查了传递给 NSWindow init 方法的所有变量。

我是否遗漏了一些非常明显的东西?代码如下:

// 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];

干杯

最佳答案

如果您需要 10.5 或更高版本,使用 NSView 的 -enterFullScreenMode:withOptions:和匹配的 -exitFullScreenModeWithOptions:。这正确地将责任转移到容器 View (它仍然可以有自己的复杂 subview 集),并使您摆脱手动弄乱窗口级别等的一些陷阱。

关于辅助显示屏上的 cocoa 全屏窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4583928/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com