Code:
void DrawScenery()
{
DebugTest[1] = DrawDibBegin(ImageHandle, HDCBack, 0, 0, BackBufferInfoPointer, 0, 0, DDF_BUFFER); // initiate to draw into back buffer // it fails, returning 0
DrawDibDraw(ImageHandle, HDCBack, 0, 0, BackgroundInfo.biWidth, BackgroundInfo.biHeight, BackgroundInfoPointer, BackgroundDataPointer, 0, 0, BackgroundInfo.biWidth, BackgroundInfo.biHeight, 0);
DrawDibDraw(ImageHandle, HDCBack, Logo.XMain, Logo.YMain, LogoInfo.biWidth, LogoInfo.biHeight, LogoInfoPointer, LogoDataPointer, 0, 0, LogoInfo.biWidth, LogoInfo.biHeight, 0);
DrawDibEnd(ImageHandle); // clear the flags
BitBlt(HDCScreen, 0, 0, WindowSizeBase.x, WindowSizeBase.y, HDCBack, 0, 0, SRCCOPY); // swaps the back and front buffers for displaying
DebugTest[2] = DrawDibBegin(ImageHandle, HDCScreen, 0, 0, ScreenBufferInfoPointer, 0, 0, 0); // initiate to draw into front buffer // it also fails, returning 0
DrawDibDraw(ImageHandle, HDCScreen, 0, 0, ScreenBufferInfo.biWidth, ScreenBufferInfo.biHeight, ScreenBufferInfoPointer, ScreenBufferPointer, 0, 0, ScreenBufferInfo.biWidth, ScreenBufferInfo.biHeight, 0);
DrawDibEnd(ImageHandle); // clear the flags
if (DebugTest[0] == 0)
{
DebugTest[0] = 1; // so this test is processed only once
// DebugTest[1] = (int)BackBuffer[0]; // record the values, 255 means a fault with BitBlt, 0 means the back buffer remains unchanged // these report 0 and 0
// DebugTest[2] = (int)BackBuffer[1439999]; // opposite corner to be sure on this
// DebugTest[1] = HDCBack; // what is the value of the back buffer's HDC? It shows a nonzero value - it's good
// DebugTest[2] = BackBufferPointer; // What is the value of the back buffer's pointer? It shows a nonzero value
// DebugTest[1] = HDCScreen; // shows a nonzero value
// DebugTest[2] = ScreenBufferPointer; // nonzero again
sprintf(DebugDetails, "The resulting values are %d and %d.", DebugTest[1], DebugTest[2]); // for debugging
MessageBox(hwnd, DebugDetails, "Debug Results", MB_OK);
}
}
void InitializeDrawing()
{
// this initializes handles and headers
ImageHandle = DrawDibOpen(); // set the DrawDib DC handle
ScreenBufferInfo.biSize = 40; // the size of the struct, always 40 in my case (due to true color being used)
ScreenBufferInfo.biWidth = WindowSizeBase.x; // display matches window interior size // 800 pixels
ScreenBufferInfo.biHeight = WindowSizeBase.y; // 600 pixels
ScreenBufferInfo.biPlanes = 1; // always 1
ScreenBufferInfo.biBitCount = 24; // number of bits per pixel, always to be 24 for the display
ScreenBufferInfo.biCompression = BI_RGB; // no compression used
ScreenBufferInfo.biSizeImage = ScreenBufferInfo.biWidth*ScreenBufferInfo.biHeight*3; // width times height times bitcount divided by 8 gives the image data size
ScreenBufferInfo.biXPelsPerMeter = 2835; // resolution in pixels per meter
ScreenBufferInfo.biYPelsPerMeter = 2835;
ScreenBufferInfo.biClrUsed = 0; // always 0 in my case
ScreenBufferInfo.biClrImportant = 0; // same here
ScreenBufferInfoPointer = &ScreenBufferInfo; // set the pointers
ScreenBufferPointer = &ScreenBuffer;
// Back buffer is identical in every way
BackBufferInfo.biSize = 40; // the size of the struct, always 40 in my case (due to true color being used)
BackBufferInfo.biWidth = WindowSizeBase.x; // display matches window interior size // 800 pixels
BackBufferInfo.biHeight = WindowSizeBase.y; // 600 pixels
BackBufferInfo.biPlanes = 1; // always 1
BackBufferInfo.biBitCount = 24; // number of bits per pixel, always to be 24 for the display
BackBufferInfo.biCompression = BI_RGB; // no compression used
BackBufferInfo.biSizeImage = BackBufferInfo.biWidth*BackBufferInfo.biHeight*3; // width times height times bitcount divided by 8 gives the image data size
BackBufferInfo.biXPelsPerMeter = 2835; // resolution in pixels per meter
BackBufferInfo.biYPelsPerMeter = 2835;
BackBufferInfo.biClrUsed = 0; // always 0 in my case
BackBufferInfo.biClrImportant = 0; // same here
BackBufferInfoPointer = &BackBufferInfo; // set the pointers
BackBufferPointer = &BackBuffer;
}
These two functions are called from within the main function.