views:

361

answers:

1

I have a graphical app that needs to test the resolution of the display it is starting up on in Mac OS X to ensure it is not larger than the resolution. This is done before the window itself is initialized.

If there is more than one display, it needs to be the primary display. This is the display that hardware accelerated (OpenGL) apps will start up on in Full Screen, and is typically the display that has the menu bar at the top.

In Windows, I can successfully use GetSystemMetrics(). How can I do this on OS X?

+4  A: 

Using CoreGraphics:

CGRect mainMonitor = CGDisplayBounds(CGMainDisplayID());
CGFloat monitorHeight = CGRectGetHeight(mainMonitor);
CGFloat monitorWidth = CGRectGetWidth(mainMonitor);

More information at Apple's Quartz Display Services Reference.

Dan Udey
Note for future generations: this code uses Carbon, so it will not work in 64-bit applications on Leopard or Snow Leopard.
Dan Udey