Code:
//get a copy of the screen DC
HDC hdc = GetDC(NULL); //NULL is the main screen IIRC, might want to check this
//and create our memDC
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP A = LoadBitmap(GetModuleHandle(NULL), "Somepicture.bmp");
HBITMAP B = LoadBitmap(GetModuleHandle(NULL), "Anotherpicture.bmp");
//variable to hold the default 1x1 BITMAP already in the DC you created
HBITMAP* origBMP = NULL;
//'catch' the default BITMAP pushed out by you selecting a BITMAP into the DC
origBMP = (HBITMAP*)SelectObject(hdcMem, A);
//draw
BitBlt(hdc, 0, 0, 32, 32, hdcMem, 0, 0, SRCCOPY);
//when we select BITMAP 'B' into the DC, BITMAP 'A' is pushed out.
//as we already have A in a variable, we do not need to catch it
SelectObject(hdcMem, b);
BitBlt(hdc, 32, 0, 32, 32, hdcMem, 0, 0, SRCCOPY);
//clean up
//select the default BITMAP back into the DC
//BITMAP 'B' will be pushed out, as we have this in a variable no need to catch it
SelectObject(hdcMem, origBMP);
//now memDC is contains the same GDI objects as when we creatd it we can delete it
DeleteDC(hdcMem);
//delete anything we created
DeleteObject(A);
DeleteObject(B);
//release anything we 'GetDC'ed
ReleaseDC(hdc);
>>Obviously in a real program i would not call a LoadBitmap() function everytime i drew. I would make it part of the game class construction. So if i deleted these HBITMAPS before the WM_DESTROY i am guessing i would lose the Handle to the actual files.
Yes. Make these have scope as long as your window is on screen. Create the GDIs when the window opens and when the window closes, select in the original GDIs and delete all GDIs you created.
>>GetLastError() returns an int is there a way to output this to the debugger so I can check this value?
int iErr = GetLastError()
Zero is ERROR_SUCCESS (no error) so you can write conditional code (using #ifdef __DEBUG)
Conditional Compilation (#if, #ifdef, #ifndef, #else,…#elif, #endif, and defined)
or put a conditional break point on the line (ie iErr != 0)
or put a watch on iErr in the debugger
or output to a MessageBox (possibly using FormatMessage() ).
See this for a code snippet;
Retrieving the Last-Error Code (Windows)
What the codes mean
System Error Codes (Windows)
I will try to find the time to read your code and comment.