Ive been experimentin with GDI a bit and drawing things to the screen. One of my main problems is that I can only draw to the screen once. Once I have drawn to the screen (for example) Image X, I cannot move and redraw Image X in another location. I do, in my code, Have the functionality to change the X/Y coords of my image, then call me Render function (Which simulates a WM_PAINT message).
Here is my render function for my Image:
Code:
void Image::RenderImage(HWND Hwnd, HDC DevContext, HDC Context)
{
HBITMAP OldBitmap;
BITMAP Bitmap;
BITMAPINFOHEADER BitmapInfo;
int BorderData = RGB(10, 10, 200);
if (Loaded && Renderable && ImgHeader.BitsPerPixel == 32)
{
// Clear our Bitmap
memset(&Bitmap, 0, sizeof(BITMAP));
// Create a struct ot hold the info about the image
BitmapInfo.biSize = sizeof(BitmapInfo);
BitmapInfo.biHeight = ImgHeader.Height;
BitmapInfo.biWidth = ImgHeader.Width;
BitmapInfo.biPlanes = 1;
BitmapInfo.biBitCount = ImgHeader.BitsPerPixel;
BitmapInfo.biCompression = BI_RGB;
BitmapInfo.biSizeImage = 0;
BitmapInfo.biXPelsPerMeter = BitmapInfo.biYPelsPerMeter = 10000;
BitmapInfo.biClrUsed = BitmapInfo.biClrImportant = 0;
// Create a DIB from our TGA data
ImgMap = CreateDIBitmap(DevContext, &BitmapInfo, CBM_INIT, Img.ImageData, (BITMAPINFO *) &BitmapInfo, DIB_RGB_COLORS);
// Set the position and Draw data
OldBitmap = (HBITMAP) SelectObject(Context, ImgMap);
GetObject(ImgMap, sizeof(Bitmap), &Bitmap);
BitBlt(DevContext, RasterX, RasterY, Bitmap.bmWidth, Bitmap.bmHeight, Context, 0, 0, MERGECOPY);
// Swap buffers
SelectObject(Context, OldBitmap);
}
}
This function is called from my WndProc function that recieves the WM_PAINT message:
Code:
void GDIHandler::Render()
{
POINT MousePos;
PAINTSTRUCT Paint;
// Start the Drawing Process
HDC CurrentDeviceContext = BeginPaint(WindowHwnd, &Paint);
HDC DeviceContextMem = CreateCompatibleDC(CurrentDeviceContext);
GetCursorPos(&MousePos);
SetBkMode(CurrentDeviceContext, TRANSPARENT);
MyImage->RenderImage(WindowHwnd, CurrentDeviceContext, DeviceContextMem);
DeleteDC(DeviceContextMem);
// Finish the drawing process
EndPaint(WindowHwnd, &Paint);
}
Ive been trying to debug this all weekend, Can someone please shed some insight on what Im doing wrong?