Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Adjusting Display Modes

The Quartz Display Services API provides several functions that adjust the display mode:

If you want to adjust the display mode, you first need to capture the display, as shown in Listing 3-4. The Quartz Display Services function CGDisplaySwitchToMode switches to the display mode returned by the function CGDisplayBestModeForParameters, which in this case, is the best display mode for the main display with a bit depth of 32 bits per pixel and a screen resolution of 1024 by 768 pixels. The display mode that's returned is not always what you asked for. It's the closest mode for the given parameter. The last parameter passed to this function—exactMatch—specifies whether the returned display mode matches exactly. If you don't need this information, you can pass NULL. When your application quits, Quartz Display Services automatically restores the user’s display settings.

Note: Calling CGDisplaySwitchToMode does not guarantee that the display mode switches successfully. Displays have physical limitations that can prevent them from operating in a particular mode.

Listing 3-4  Adjusting the display mode

CGDisplayCapture (kCGDirectMainDisplay ) ;
CGDisplaySwitchToMode (kCGDirectMainDisplay,
            CGDisplayBestModeForParameters (kCGDirectMainDisplay,
                                 32, 1024, 768, NULL) );

Listing 3-5 shows how to switch the main display to a pixel depth of 32 bits per pixel, a resolution of 640 x 480, and a refresh rate of 60 Hz. A detailed explanation for each numbered line of code appears following the listing.

Listing 3-5  Switching the resolution of a display

CFDictionaryRef displayMode ;
CFNumberRef number ;
boolean_t exactMatch ;
 
CGDisplayCapture (kCGDirectMainDisplay); // 1
displayMode =
    CGDisplayBestModeForParametersAndRefreshRate (kCGDirectMainDisplay,
                            32,640,480,60,&exactMatch); // 2
if (exactMatch){        // 3
     CGDisplaySwitchToMode (kCGDirectMainDisplay, displayMode);
}
else {
    // Your code to take appropriate action
}
// Run the event loop.
CGReleaseAllDisplays(); // 4

Here's what the code does:

  1. Captures the main display.

  2. Requests a display mode with a depth of 32 bits per pixel, a resolution 640 x 480, and a refresh rate 60 Hz. The function finds the best match for these parameters.

  3. If there is an exact match, then switches to the display mode.

  4. Before the application quits, releases all displays.



< Previous PageNext Page > Hide TOC


Last updated: 2008-06-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice