Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACaveli7

macrumors newbie
Original poster
Oct 15, 2010
23
0
I have heard that you can use NSScreen frame to get the current resolution of the screen, is there an alternative version that doesn't need objective c code?
 
Even if there weren't, it would be sufficient to declare:

ScreenFrame.h:

Code:
#ifdef __cplusplus
extern "C" {
#endif

CGRect GetMainScreenFrame();

#ifdef __cplusplus
}
#endif

ScreenFrame.m:

Code:
CGRect GetMainScreenFrame()
{
    return [[NSScreen mainScreen] frame];
}

Or even just rename your .cpp file to .mm (Objective-C++) and put the [[NSScreen mainScreen] frame] right in there. Apple allow Objective-C, C and C++ to be freely intermingled.

Note that you'll get the frame of the main screen. You can use [[window screen] frame] to get the frame for the screen that a particular NSWindow is on.
 
^ NScreen should only be used within a proper GUI app. Otherwise you should use CGDisplay.

IMO, NSScreen is a poorly written API and the CGDisplay functions are much clearer. e.g. mainScreen != CGMainDisplayID
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.