1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| HBITMAP CREATE_HANDLE_FROM_BITMAP(TBitmap * pBitmap)
{
HBITMAP hBitmap;
HDC hDC;
long width, height, start, retour;
int ligne, reste, alignement;
static int ret;
char car[4] = {0, 0, 0, 0};
UCHAR * lpBits;
width = pBitmap->Entete2.biWidth;
height = pBitmap->Entete2.biHeight;
reste = (width*sizeof(TCouleur))%4;
if (reste > 0)
{
alignement = 4-reste;
}
else
{
alignement = 0;
}
lpBits = (UCHAR *)malloc(height*(width*sizeof(TCouleur)+alignement)*sizeof(UCHAR));
start = 0;
for (ligne = 0; ligne < height; ligne++)
{
memcpy(&lpBits[start], &pBitmap->pixels[ligne*width], width*sizeof(TCouleur));
memcpy(&lpBits[start+width*sizeof(TCouleur)], car, alignement*sizeof(UCHAR));
start += width*sizeof(TCouleur)+alignement;
}
hDC = GetDC(NULL);
hBitmap = CreateCompatibleBitmap(hDC, width, height);
start = 0;
for (ligne = 0; ligne < height; ligne++)
{
retour = SetDIBits(hDC, hBitmap, ligne, 1, &lpBits[start], (BITMAPINFO *)&pBitmap->Entete2, DIB_RGB_COLORS);
/*
if (retour == 0)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
MessageBox( NULL, (char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
}
*/
start += width*sizeof(TCouleur)+alignement;
}
ReleaseDC(NULL,hDC);
DeleteDC (hDC);
//free(lpBits);
return hBitmap;
} |
Partager