Code:
int DrawSprite(HDC hdc, HBITMAP hbmColour,int x, int y, COLORREF crTransparent)
{
HDC hdcMem, hdcMem2;
HBITMAP hbmMask, hOldBitmap, hOldBitmap2;
BITMAP bm;
GetObject(hbmColour, sizeof(BITMAP), &bm);
hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
hdcMem = CreateCompatibleDC(hdc);
hdcMem2 = CreateCompatibleDC(hdc);
hOldBitmap = SelectObject(hdcMem, hbmColour);
hOldBitmap2 = SelectObject(hdcMem2, hbmMask);
SetBkColor(hdcMem, crTransparent);
BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCAND);
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);
SelectObject(hdcMem, hOldBitmap);
SelectObject(hdcMem2, hOldBitmap2);
DeleteDC(hdcMem);
DeleteDC(hdcMem2);
DeleteObject(hbmMask);
return 0;
}