View Full Version : C++ version of NSScreen frame

Oct 22, 2010, 08:50 AM
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?

Oct 22, 2010, 11:04 AM
Yes - look in CGDirectDisplay.h

Thomas Harte
Oct 22, 2010, 02:51 PM
Even if there weren't, it would be sufficient to declare:


#ifdef __cplusplus
extern "C" {

CGRect GetMainScreenFrame();

#ifdef __cplusplus


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.

Oct 22, 2010, 03:20 PM
^ 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