May 18th, 1999, 03:42 AM
Please tell me what's wrong with my code below.
I guess it's related with inproper palette setting,
but don't know exactly what is the problem.
// Make a BLUE palette
HPALETTE CreateSpecialEffectPal()
{
HPALETTE hpal;
LPLOGPALETTE logpal;
int i;
logpal = malloc(sizeof(LOGPALETTE) + 256*sizeof(PALETTEENTRY));
logpal->palVersion = 0x300;
logpal->palNumEntries = count_pal;
for(i=0; i<256; i++)
{
logpal->palPalEntry[i].peRed = 0;
logpal->palPalEntry[i].peGreen = 0;
logpal->palPalEntry[i].peBlue = 255;
logpal->palPalEntry[i].peFlags = 0;
}
hpal=CreatePalette(logpal);
free(logpal);
return hpal;
}
// width and height are hBitmap's width and height.
// hDC is a screen DC.
void Display(HDC hDC, HBITMAP hBitmap, HPALETTE hpal, int width, int height)
{
HDC hSrcMemDC, hSrcMemDC2;
HPALETTE hpal2;
HBITMAP hBitmap2;
hSrcMemDC = CreateCompatibleDC(hDC);
hSrcMemDC2 = CreateCompatibleDC(hDC);
hBitmap2 = CreateCompatibleBitmap(hDC, width, height);
SelectPalette(hSrcMemDC, hpal, TRUE);
RealizePalette(hSrcMemDC);
SelectObject(hSrcMemDC, hBitmap);
// Copy the bitmap from the first MemDC.
SelectPalette(hSrcMemDC2, hpal, TRUE);
RealizePalette(hpal);
SelectObject(hSrcMemDC2, hBitmap2);
BitBlt(hSrcMemDC2, 0, 0, width, height, hSrcMemDC, 0, 0, SRCCOPY);
hpal2 = CreateSpecialEffectPal(hpal);
SelectPalette(hDC, hpal2, FALSE);
RealizePalette(hpal2);
// PROBLEM! Two blits don't produce the same images
// the first one is correct(BLUE rectangle), but the second is weird.
// I guess there was a palette problem with the second, but don't know what.
BitBlt(hDC, 0, 0, width, height, hSrcMemDC, 0, 0, SRCCOPY);
BitBlt(hDC, width, 0, width, height, hSrcMemDC2, 0, 0, SRCCOPY);
// Do clean up
....
}
I guess it's related with inproper palette setting,
but don't know exactly what is the problem.
// Make a BLUE palette
HPALETTE CreateSpecialEffectPal()
{
HPALETTE hpal;
LPLOGPALETTE logpal;
int i;
logpal = malloc(sizeof(LOGPALETTE) + 256*sizeof(PALETTEENTRY));
logpal->palVersion = 0x300;
logpal->palNumEntries = count_pal;
for(i=0; i<256; i++)
{
logpal->palPalEntry[i].peRed = 0;
logpal->palPalEntry[i].peGreen = 0;
logpal->palPalEntry[i].peBlue = 255;
logpal->palPalEntry[i].peFlags = 0;
}
hpal=CreatePalette(logpal);
free(logpal);
return hpal;
}
// width and height are hBitmap's width and height.
// hDC is a screen DC.
void Display(HDC hDC, HBITMAP hBitmap, HPALETTE hpal, int width, int height)
{
HDC hSrcMemDC, hSrcMemDC2;
HPALETTE hpal2;
HBITMAP hBitmap2;
hSrcMemDC = CreateCompatibleDC(hDC);
hSrcMemDC2 = CreateCompatibleDC(hDC);
hBitmap2 = CreateCompatibleBitmap(hDC, width, height);
SelectPalette(hSrcMemDC, hpal, TRUE);
RealizePalette(hSrcMemDC);
SelectObject(hSrcMemDC, hBitmap);
// Copy the bitmap from the first MemDC.
SelectPalette(hSrcMemDC2, hpal, TRUE);
RealizePalette(hpal);
SelectObject(hSrcMemDC2, hBitmap2);
BitBlt(hSrcMemDC2, 0, 0, width, height, hSrcMemDC, 0, 0, SRCCOPY);
hpal2 = CreateSpecialEffectPal(hpal);
SelectPalette(hDC, hpal2, FALSE);
RealizePalette(hpal2);
// PROBLEM! Two blits don't produce the same images
// the first one is correct(BLUE rectangle), but the second is weird.
// I guess there was a palette problem with the second, but don't know what.
BitBlt(hDC, 0, 0, width, height, hSrcMemDC, 0, 0, SRCCOPY);
BitBlt(hDC, width, 0, width, height, hSrcMemDC2, 0, 0, SRCCOPY);
// Do clean up
....
}