Bonjour,
dans mon appli j'ai besoin d'afficher plusieurs image bitmap. J'arrive à en afficher une avec ce code.
où monbouton est une variable membre de ma classe.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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); }
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:
ça affiche bien une image, mais une seule, celle dans le second CStatic (oui monbouton est un CStatic, enfin un tableau CStatic monbouton(2)).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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); } }
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?
Partager