je coince sur un problème d'affichage d'une image. Dans un CView, le onPaint avec le code suivant fonctionne très bien :
Par contre, si je remplace les CBitmap par des Gdi+ Bitmap, plus rien n'est affiché :
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 CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CBitmap BmpLoaded; CDC MemDC; // Create a memory device compatible with the above CPaintDC variable MemDC.CreateCompatibleDC(&dc); BmpLoaded.DeleteObject(); HBITMAP hBitmap = NULL; hBitmap = (HBITMAP)LoadImage(NULL, _T("c:\\image.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); BmpLoaded.Attach(hBitmap); // Select the new bitmap CBitmap *BmpPrevious = MemDC.SelectObject(&BmpLoaded); // Copy the bits from the memory DC into the current dc CRect rect; this->GetClientRect(&rect); dc.BitBlt(0, 0, rect.Width(), rect.Height(), &MemDC, 0, 0, SRCCOPY); // Restore the old bitmap dc.SelectObject(BmpPrevious);
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 CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CDC MemDC; // Create a memory device compatible with the above CPaintDC variable MemDC.CreateCompatibleDC(&dc); Bitmap * test = Bitmap::FromFile(_T("c:\\image.bmp")); // Select the new bitmap HGDIOBJ prevObj = MemDC.SelectObject(test); // Copy the bits from the memory DC into the current dc CRect rect; this->GetClientRect(&rect); dc.BitBlt(0, 0, rect.Width(), rect.Height(), &MemDC, 0, 0, SRCCOPY); // Restore the old bitmap dc.SelectObject(prevObj);
Une idée de pourquoi la seconde version n'affiche rien ?
Partager