DirectX SDK

Creating a Palette in Windowed Mode

[C++]

The following example illustrates how to create a DirectDraw palette in nonexclusive (windowed) mode. In order for your palette to work correctly, it is vital that you set up every one of the 256 entries in the PALETTEENTRY structure that you submit to the IDirectDraw7::CreatePalette method.

LPDIRECTDRAW7        lpDD; // Assumed to be initialized previously 
PALETTEENTRY         pPaletteEntry[256]; 
int                  index; 
HRESULT              ddrval; 
LPDIRECTDRAWPALETTE2 lpDDPal; 
 
// First set up the Windows static entries. 
for (index = 0; index < 10 ; index++) 
{ 
    // The first 10 static entries: 
    pPaletteEntry[index].peFlags = PC_EXPLICIT; 
    pPaletteEntry[index].peRed = index; 
    pPaletteEntry[index].peGreen = 0; 
    pPaletteEntry[index].peBlue = 0; 
 
    // The last 10 static entries: 
    pPaletteEntry[index+246].peFlags = PC_EXPLICIT; 
    pPaletteEntry[index+246].peRed = index+246; 
    pPaletteEntry[index+246].peGreen = 0; 
    pPaletteEntry[index+246].peBlue = 0; 
} 
 
// Now set up private entries. In this example, the first 16 
// available entries are animated. 
for (index = 10; index < 26; index ++) 
{ 
    pPaletteEntry[index].peFlags = PC_NOCOLLAPSE|PC_RESERVED; 
    pPaletteEntry[index].peRed = 255; 
    pPaletteEntry[index].peGreen = 64; 
    pPaletteEntry[index].peBlue = 32; 
} 
 
// Now set up the rest, the nonanimated entries. 
for (; index < 246; index ++) // Index is set up by previous for loop 
{ 
    pPaletteEntry[index].peFlags = PC_NOCOLLAPSE; 
    pPaletteEntry[index].peRed = 25; 
    pPaletteEntry[index].peGreen = 6; 
    pPaletteEntry[index].peBlue = 63; 
} 
 
// All 256 entries are filled. Create the palette. 
ddrval = lpDD->CreatePalette(DDPCAPS_8BIT, pPaletteEntry, 
    &lpDDPal,NULL); 
[Visual Basic]

The following example illustrates how to create a DirectDraw palette in nonexclusive (windowed) mode. In order for your palette to work correctly, it is vital that you set up every one of the 256 entries in the PALETTEENTRY type that you submit to the DirectDraw7.CreatePalette method.

Private Sub Form_Load()
    
    Dim pPaletteEntry(255) As PALETTEENTRY
    Dim index As Long
    Dim ddpal As DirectDrawPalette
     
    'First set up the windows static entries.
    For index = 0 To 9
        'The first 10 static entries.
        pPaletteEntry(index).flags = PC_EXPLICIT
        pPaletteEntry(index).red = index
        pPaletteEntry(index).green = 0
        pPaletteEntry(index).blue = 0
        
        'The last 10 static entries
        pPaletteEntry(index + 246).flags = PC_EXPLICIT
        pPaletteEntry(index + 246).red = index + 246
        pPaletteEntry(index + 246).green = 0
        pPaletteEntry(index + 246).blue = 0
    Next
    
    'Now set up private entries. In this example, the first
    '16 available entried are animated.
    For index = 10 To 25
        pPaletteEntry(index).flags = PC_NOCOLLAPSE Or PC_RESERVED
        pPaletteEntry(index).red = 255
        pPaletteEntry(index).green = 64
        pPaletteEntry(index).blue = 32
    Next
    
    'Now set up the rest, the non-animated entries.
    For index = 26 To 246
        pPaletteEntry(index).flags = PC_NOCOLLAPSE
        pPaletteEntry(index).red = 25
        pPaletteEntry(index).green = 6
        pPaletteEntry(index).blue = 63
    Next
    
    'All 256 entries are filled. Create the palette.
    Set ddpal = dd.CreatePalette(DDPCAPS_8BIT, pPaletteEntry())