Je courais ce code suivant,Bitblt noir
HDC hdc;
HDC hdcMem;
HBITMAP bitmap;
RECT c;
GetClientRect(viewHandle, &c);
// instead of BeginPaint use GetDC or GetWindowDC
hdc = GetDC(viewHandle);
hdcMem = CreateCompatibleDC(hdc);
// always create the bitmap for the memdc from the window dc
bitmap = CreateCompatibleBitmap(hdc,c.right-c.left,200);
SelectObject(hdcMem, bitmap);
// only execute the code up to this point one time
// that is, you only need to create the back buffer once
// you can reuse it over and over again after that
// draw on hdcMem
// for example ...
Rectangle(hdcMem, 126, 0, 624, 400);
// when finished drawing blit the hdcMem to the hdc
BitBlt(hdc, 0, 0, c.right-c.left,200, hdcMem, 0, 0, SRCCOPY);
// note, height is not spelled i before e
// Clean up - only need to do this one time as well
DeleteDC(hdcMem);
DeleteObject(bitmap);
ReleaseDC(viewHandle, hdc);
Le code est très bien. Mais je vois de la couleur noire autour de ce rectangle. Pourquoi donc? Here is an example image.
Vous devriez enregistrer le résultat de votre SelectObject et le restaurer avant la suppression, pour éviter les problèmes de Windows, vous évitez peut-être des plantages en raison de la sortie du DC mais d'autres effets secondaires: HBITMAP saveBM; .. saveBM = SelectObject (hdcMem, bitmap); ... SelectObject (hdcMem, saveBM); DeleteObject (bitmap); –