如何在Mac OS X Lion的双屏幕上显示 [英] How to display on dual screens on Mac OS X Lion

查看:93
本文介绍了如何在Mac OS X Lion的双屏幕上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序同时显示在笔记本电脑屏幕和带有两个单独的NSWindow的外部屏幕上,我找不到有关如何实现它的任何文档.有提示吗?

I want my app to be displayed on both laptop screen and an external screen with two separated NSWindow, I can't find any document about how to implement it. Any hint?

谢谢

推荐答案

The OS X OpenGL Programming Guide shows the old way of making a full-screen window:

  1. 在您要接管的显示器上创建一个屏幕大小的窗口:

  1. Create a screen-sized window on the display you want to take over:

NSRect mainDisplayRect = [[NSScreen mainScreen] frame];
NSWindow *fullScreenWindow = [[NSWindow alloc] initWithContentRect: mainDisplayRect styleMask:NSBorderlessWindowMask
    backing:NSBackingStoreBuffered defer:YES];

  • 将窗口级别设置为在菜单栏上方.

  • Set the window level to be above the menu bar.:

    [fullScreenWindow setLevel:NSMainMenuWindowLevel+1];
    

  • 执行所需的任何其他窗口配置:

  • Perform any other window configuration you desire:

    [fullScreenWindow setOpaque:YES];
    [fullScreenWindow setHidesOnDeactivate:YES];
    

  • 使用双缓冲OpenGL上下文创建视图并将其附加到窗口:

  • Create a view with a double-buffered OpenGL context and attach it to the window:

    NSOpenGLPixelFormatAttribute attrs[] =
    {
        NSOpenGLPFADoubleBuffer,
        0
    };
    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
    
    NSRect viewRect = NSMakeRect(0.0, 0.0, mainDisplayRect.size.width, mainDisplayRect.size.height);
    MyOpenGLView *fullScreenView = [[MyOpenGLView alloc] initWithFrame:viewRect pixelFormat: pixelFormat];
    [fullScreenWindow setContentView: fullScreenView];
    

  • 显示窗口:

  • Show the window:

    [fullScreenWindow makeKeyAndOrderFront:self];
    

  • 您可以使用此方法在要绘制到的每个屏幕上创建窗口.如果使用此方法仅在一个屏幕上创建窗口,则另一个屏幕将继续正常运行,而不是被涂黑或覆盖在愚蠢的亚麻质地中.根据您的用途,您可能不想setHidesOnDeactivate.

    You can use this method to create windows on each screen that you want to draw to. If you use this to create a window on only one screen, the other screen will continue to function normally, instead of being blacked out or covered in a stupid linen texture. Depending on your use, you may not want to setHidesOnDeactivate.

    还有一些较低级别的API可以完全控制屏幕并阻止OS或任何其他应用程序绘制到屏幕上,但是很少有理由使用它们.

    There are also lower-level APIs to take control of a screen completely and prevent the OS or any other application from drawing to the screen, but their use is seldom justified.

    如果要使一个GL上下文具有跨多个屏幕的渲染,则需要创建一个具有NSRect且跨所有屏幕的单个窗口.如果屏幕分辨率不匹配,则可能会导致部分窗口不可见,并且低端图形芯片可能会出现问题.

    If you want to have one GL context with the render spanning multiple screens, you need to create a single window with a NSRect that spans all the screens. If the screen resolutions aren't matched, this may result in part of your window not being visible, and low-end graphics chips may have some problems.

    这篇关于如何在Mac OS X Lion的双屏幕上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆