次の方法で共有


Best-Matchピクセル形式の選択と設定

このトピックでは、デバイス コンテキストをピクセル形式に一致させる手順について説明します。

デバイス コンテキストとピクセル形式の最適な一致を取得するには

  1. PIXELFORMATDESCRIPTOR 構造体で目的のピクセル形式を指定します。

  2. ChoosePixelFormat を呼び出します。

    ChoosePixelFormat 関数はピクセル形式インデックスを返します。このインデックスを SetPixelFormat に渡して、最適なピクセル形式の一致をデバイス コンテキストの現在のピクセル形式として設定できます。

次のコード サンプルは、上記の手順を実行する方法を示しています。

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; 
 
// get the device context's best, available pixel format match  
iPixelFormat = ChoosePixelFormat(hdc, &pfd); 
 
// make that match the device context's current pixel format  
SetPixelFormat(hdc, iPixelFormat, &pfd);