Setting Color Keys

You can set the source or destination color key for a surface either when creating it or afterwards.

To set a color key or keys when creating a surface, you assign the appropriate color values to one or both of the ddckCKSrcBlt and ddckCKDestBlt members of the DDSURFACEDESC2 structure that is passed to IDirectDraw4::CreateSurface. To enable the color key for blitting, you must also include one or both of DDSD_CKSRCBLT or DDSD_CKDESTBLT in the dwFlags member.

To set a color key for an existing surface you use the IDirectDrawSurface4::SetColorKey method. You specify a key in the lpDDColorKey parameter and set either DDCKEY_SRCBLT or DDCKEY_DESTBLT in the dwFlags parameter to indicated whether you are setting a source or destination key. If the DDCOLORKEY structure contains a range of colors, you must also set the DDCKEY_COLORSPACE flag. If this flag is not set, only the dwColorSpaceLowValue member of the structure is used.