Personally i do this (pulled directly from my current DDraw project, getting an inside peek and all, you lucky bastard, you ):
Code:
DWORD DDColorMatch(IDirectDrawSurface7 * pdds, COLORREF rgb)
{
COLORREF rgbT;
HDC hdc;
DWORD dw = CLR_INVALID;
DDSURFACEDESC2 ddsd;
HRESULT hres;
// Match color
if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
{
rgbT = GetPixel(hdc, 0, 0); // Save current pixel value
SetPixel(hdc, 0, 0, rgb); // Set our value
pdds->ReleaseDC(hdc);
}
//lock the surface
ddsd.dwSize = sizeof(ddsd);
while ((hres = pdds->Lock(NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING)
;
if (hres == DD_OK)
{
dw = *(DWORD *) ddsd.lpSurface;
if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; // Mask
pdds->Unlock(NULL);
}
//Put it back
if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
{
SetPixel(hdc, 0, 0, rgbT);
pdds->ReleaseDC(hdc);
}
return dw;
}
//-----------------------------------------------------------------------------
LPDIRECTDRAWSURFACE7 CSurfaceManager::ColorKeyEnable(LPDIRECTDRAWSURFACE7 pTexture)
{
DDCOLORKEY ddck;
ddck.dwColorSpaceLowValue = DDColorMatch(pTexture, RGB(255, 0, 255));
ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue;
pTexture->SetColorKey(DDCKEY_SRCBLT, &ddck);
return pTexture;
}
//-----------------------------------------------------------------------------
It sets the color key to (255,0,255) which is what i use for everything, but you can easily change the functions to pass in any value you want.
Used just like this:
pTexture = ColorKeyEnable(pTexture);