initialisation multiple de CPaintDC
Bonjour,
dans mon appli j'ai besoin d'afficher plusieurs image bitmap. J'arrive � en afficher une avec ce code.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| void CDialog1::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect client;
HBITMAP bit;
BITMAP bitmap;
CWnd *fenetre=monbouton.GetWindow(GW_HWNDLAST);
CPaintDC hdc(fenetre);
bit= (HBITMAP) LoadImage(NULL,"mer.bmp", IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
GetObject(bit, sizeof(BITMAP), &bitmap);
int surf_width = bitmap.bmWidth;
int surf_height = bitmap.bmHeight;
HDC bit_dc = CreateCompatibleDC(hdc);
SelectObject(bit_dc, bit);
CDC *test=monbouton.GetDC();
monbouton.GetClientRect(&client);
StretchBlt(hdc,0,0, client.right, client.bottom,bit_dc, 0,0,surf_width,surf_height, SRCCOPY);
} |
o� monbouton est une variable membre de ma classe.
Pour en afficher plusieurs (le nombre est variable, j'ai besoin de r�initialiser les variable fenetre et hdc. Je ne sais pas comment faire.
voici le code que j'utilise actuellement:
Code:
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
| void CbddPhoto::OnPaint()
{
CPaintDC dc(this); // device context for painting
int i;
CRect client;
Tableau<Image> tab1(2);
HBITMAP bit;
BITMAP bitmap;
// initialisation des variables fenetres et hdc
// initialisation des noms
tab1[0].m_Nom="mer.bmp";
tab1[1].m_Nom="ng.bmp";
// boucle d'affichage
for (i=0;i<tab1.LireTaille();i++)
{
CWnd *fenetre=myButton1[i].GetWindow(GW_HWNDLAST);
CPaintDC hdc(fenetre);
bit= (HBITMAP) LoadImage(NULL, tab1[i].m_Nom, IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
GetObject(bit, sizeof(BITMAP), &bitmap);
int surf_width = bitmap.bmWidth;
int surf_height = bitmap.bmHeight;
HDC bit_dc = CreateCompatibleDC(hdc);
SelectObject(bit_dc, bit);
CDC *test=myButton1[i].GetDC();
myButton1[i].GetClientRect(&client);
StretchBlt(hdc,0,0, client.right, client.bottom,bit_dc, 0,0,surf_width,surf_height, SRCCOPY);
}
} |
�a affiche bien une image, mais une seule, celle dans le second CStatic (oui monbouton est un CStatic, enfin un tableau CStatic monbouton(2)).
Alors j'ai plusieurs question
1- Est ce que CStatic monbouton(2) cr�e bien un tableau de 2 boutons? (apparemment oui, �a me les affiches.
2- le probl�me peut-il venir de l'initialisation de fenetre et hdc?