Salut. J'ai trouvé la réponse sur ce site justement.
Tout d'abord tu charges le BMP ou JPEG ou GIF depuis le fichier sur le disque.
HBITMAP LoadAnImage(char* FileName)
{
// Use IPicture stuff to use JPG / GIF files
IPicture* p;
IStream* s;
// IPersistStream* ps;
HGLOBAL hG;
void* pp;
FILE* fp;
// Read file in memory
fp = fopen(FileName,"rb");
if (!fp)
return NULL;
fseek(fp,0,SEEK_END);
int fs = ftell(fp);
fseek(fp,0,SEEK_SET);
hG = GlobalAlloc(GPTR,fs);
if (!hG)
{
fclose(fp);
return NULL;
}
pp = (void*)hG;
fread(pp,1,fs,fp);
fclose(fp);
// Create an IStream so IPicture can
CreateStreamOnHGlobal(hG,false,&s);
if (!s)
{
GlobalFree(hG);
return NULL;
}
OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);
if (!p)
{
s->Release();
GlobalFree(hG);
return NULL;
}
s->Release();
GlobalFree(hG);
HBITMAP hB = 0;
p->get_Handle((unsigned int*)&hB);
// Copy the image. Necessary, because upon p's release,
// the handle is destroyed.
HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,
LR_COPYRETURNORG);
p->Release();
return hBB;
}
Ca te renvoie un HBITMAP que tu affiches ensuite dans ton OnDraw de cette facon:
HDC hdcBits;
BITMAP bm;
hdcBits = CreateCompatibleDC(pDC->m_hDC);
GetObject (Himage, sizeof(BITMAP), &bm);
SelectObject(hdcBits,Himage);
//les X,Y des coins sont en pixels de l'ecran donc le (0;0) est en haut à gauche de ta fenetre.
StretchBlt(pDC->m_hDC,
X_CoinHautGauche,
Y_CoinHautGauche,
int( X_CoinBasDroite-X_CoinHautGauche),
int(-(Y_CoinBasDroite-Y_CoinHautGauche)),
hdcBits,
0,
0,
bm.bmWidth,
bm.bmHeight,
SRCAND);
DeleteDC(hdcBits);
Attention StretchBlt est utile pour etirer ton image d'un rectangle vers un autre. Sinon tu as BitBlt que tu peux utiliser. (Remarque : StretchBlt marche bien comme ca donc ... au moins tu auras toujours la possibilité avec StretchBlt d'etirer ton image pour remplir tout ton arriere plan par exemple ;) ).
J'espère que ca t'aide.
Aethys