Hello,
I'm trying to display a bitmap (Well, DIB in Microsoft-speak) in a window using the WM_PAINT message. This works fine when it initially loads up, but if I drag another window over it and then drag it back it gets all corrupted. I'm using:-
Code:
// g_lpData is a pointer to the image data
// g_lpBi is a pointer to the image's BITMAPINFO
// g_iScrollX, g_iScrollY are offsets set by the scroll bars
case WM_PAINT:
{
PAINTSTRUCT ps;
if (g_lpData) // We have something to draw
{
BeginPaint(hwnd, &ps);
ps.rcPaint.right -= ps.rcPaint.left;
ps.rcPaint.bottom -= ps.rcPaint.top;
if (ps.rcPaint.right > g_lpBi->bmiHeader.biWidth)
ps.rcPaint.right = g_lpBi->bmiHeader.biWidth;
if (ps.rcPaint.bottom > -g_lpBi->bmiHeader.biHeight)
ps.rcPaint.bottom = -g_lpBi->bmiHeader.biHeight;
if (ps.rcPaint.left < g_lpBi->bmiHeader.biWidth && ps.rcPaint.top < -g_lpBi->bmiHeader.biHeight)
StretchDIBits(ps.hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, ps.rcPaint.left + g_iScrollX, ps.rcPaint.top + g_iScrollY, ps.rcPaint.right, ps.rcPaint.bottom, g_lpData, g_lpBi, DIB_RGB_COLORS, SRCCOPY);
EndPaint(hwnd, &ps);
}
break;
}
I know most people just draw the entire bitmap all at once, but I think that's a bit of a waste doing that every time a window is moved a pixel over the bitmap. Can anyone solve this for me please?