The ChoosePixelFormat function attempts to match an appropriate pixel format supported by a device context to a given pixel format specification.
int ChoosePixelFormat(
HDC hdc, // device context to search for a best pixel format
// match
CONST PIXELFORMATDESCRIPTOR * ppfd
// pixel format for which a best match is sought
);
If any of the following flags are set, the ChoosePixelFormat function attempts to match pixel formats that also have that flag or flags set. Otherwise, ChoosePixelFormat ignores that flag in the pixel formats:
PFD_DRAW_TO_WINDOW
PFD_DRAW_TO_BITMAP
PFD_SUPPORT_GDI
PFD_SUPPORT_OPENGL
If any of the following flags are set, ChoosePixelFormat attempts to match pixel formats that also have that flag or flags set. Otherwise, it attempts to match pixel formats without that flag set:
PFD_DOUBLEBUFFER
PFD_STEREO
If the following flag is set, the function ignores the PFD_DOUBLEBUFFER flag in the pixel formats:
PFD_DOUBLEBUFFER_DONTCARE
If the following flag is set, the function ignores the PFD_STEREO flag in the pixel formats:
PFD_STEREO_DONTCARE
PFD_TYPE_RGBA
PFD_TYPE_COLORINDEX
PFD_MAIN_PLANE
PFD_OVERLAY_PLANE
PFD_UNDERLAY_PLANE
If the function succeeds, the return value is a pixel format index (one-based) that is the closest match to the given pixel format descriptor.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
You must ensure that the pixel format matched by the ChoosePixelFormat function satisfies your requirements. For example, if you request a pixel format with a 24-bit RGB color buffer but the device context offers only 8-bit RGB color buffers, the function returns a pixel format with an 8-bit RGB color buffer.
The following code sample shows how to use ChoosePixelFormat to match a specified pixel format:
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
HDC hdc;
int iPixelFormat;
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
Windows NT: Use version 3.5 and later.
Windows: Use Windows 95 and later.
Windows CE: Unsupported.
Header: Declared in wingdi.h.
Import Library: Link with gdi32.lib.
OpenGL on Windows NT and Windows 95 Overview, Win32 Functions, DescribePixelFormat, GetPixelFormat, SetPixelFormat