如何确定哪个屏幕包含菜单栏? [英] How can I detemine which screen holds the menubar?

查看:91
本文介绍了如何确定哪个屏幕包含菜单栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在可可中,当计算机有多个屏幕时,如何确定哪个屏幕包含菜单栏?

In Cocoa, how can I determine which screen holds the menubar when the computer has multiple screens?

这是我到目前为止所拥有的:

Here's what I have so far:

NSArray * screens = [NSScreen screens];
NSScreen * mainScreen = [screens objectAtIndex:0];
if ([screens count] > 1)
{
    for (NSScreen * screen in screens)
    {
        if (/* screen == the screen that holds the menubar */)
        { mainScreen = screen; break; }
    }
}

NSLog(@"the main screen is: %@", mainScreen);

注意:我尝试使用[NSScreen mainScreen],但这只是返回当前活动窗口所在的屏幕.如果我的应用程序中没有其他窗口打开,则仅返回具有菜单栏的屏幕.

Note: I tried using [NSScreen mainScreen], but that simply returns the screen on which the currently active window resides. It only returns the screen that has the menubar if there are no other windows open in my app.

推荐答案

来自

包含菜单栏的屏幕始终是screens方法返回的数组中的第一个对象(索引0).

The screen containing the menu bar is always the first object (index 0) in the array returned by the screens method.

因此您的变量mainScreen已包含它.

so your variable mainScreen already contains it.

这篇关于如何确定哪个屏幕包含菜单栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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