如何确定哪个屏幕包含菜单栏? [英] How can I detemine which screen holds the menubar?
本文介绍了如何确定哪个屏幕包含菜单栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在可可中,当计算机有多个屏幕时,如何确定哪个屏幕包含菜单栏?
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.
推荐答案
查看全文