I have read about using buffers to move a ball on the screen.
I am using C++11 on Microsoft Windows 32 bit.
No visual C++. No Visual Basic. No .NET. No Active X. Please.
Thank you.
Would you please look at what I have and adjust it to correct logic? It works but I want it to be better.
Thank you.
void DrawBall(HDC hdc, RECT* prc)
{
HDC hdcWorkingBackBuffer = CreateCompatibleDC(hdc);
HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hdcWorkingBackBuffer, hbmBuffer);
HDC hdcBacdkgroundBitmapBuffer = CreateCompatibleDC(hdc);
HBITMAP hbmOldRed =
(HBITMAP)SelectObject(hdcBacdkgroundBitmapBuffer, g_RedGreenBlue);
StretchBlt(hdcWorkingBackBuffer, 0, 0, 320, 240,
hdcBacdkgroundBitmapBuffer, 0, 0, 320, 240, SRCCOPY);
HDC hdcAnimationBuffer_001 = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcAnimationBuffer_001, g_hbmMask);
BitBlt(hdcWorkingBackBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width,
g_ballInfo.height, hdcAnimationBuffer_001, 0, 0, SRCAND);
SelectObject(hdcAnimationBuffer_001, g_hbmBall);
BitBlt(hdcWorkingBackBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width,
g_ballInfo.height, hdcAnimationBuffer_001, 0, 0, SRCPAINT);
BitBlt(hdc, 0, 0, prc->right, prc->bottom, hdcWorkingBackBuffer,
0, 0, SRCCOPY);
SelectObject(hdcAnimationBuffer_001, hbmOldRed);
DeleteDC(hdcBacdkgroundBitmapBuffer);
SelectObject(hdcAnimationBuffer_001, hbmOld);
DeleteDC(hdcAnimationBuffer_001);
SelectObject(hdcWorkingBackBuffer, hbmOldBuffer);
DeleteDC(hdcWorkingBackBuffer);
DeleteObject(hbmBuffer);
}
What I have tried:
I have studied this and I think that I am beginning to understand the creation of an animation via blitting, and more specifically how to do this with a bitmap background. But now that it works, I have been trying to further understand what it is doing.
I have added comments. I would like someone that is more advanced than me to look at it and correct where I am wrong.
It works but I want it to be better.
Thank you.