This means you need to 'catch' the GDI object when using SelectObject(), as you can not get the GDI object back out of the DC (and it may not delete while in the DC).
I am a little fuzzy on what that means. If
Code:
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP A = LoadBitmap(GetModuleHandle(NULL), "Somepicture.bmp");
HBITMAP B = LoadBitmap(GetModuleHandle(NULL), "Anotherpicture.bmp");
SelectObject(hdcMem, A);
BitBlt(hdc, 0, 0, 32, 32, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, b); //this is where you say i would have to "catch it"? Would that be with a susequent delete object call?
BitBlt(hdc, 32, 0, 32, 32, hdcMem, 0, 0, SRCCOPY);
DeleteDC(hdcMem);
Sorry if the code above is flawed i am trying to recall all functions from memory and only been using winapi for a few days. The documentation on MSDN's library website says you also have to delete each HBITMAP that uses a LoadBitmap() function. Would you delete it at then end of the program IE the when the WM_DESTROY is called?
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.
As for the compiler i am using (don't crucify me) DevC++. I am saving up for the full version of Visual C++, but at the moment this is what i am using.
Check in Task Manger to see if your app is leaking GDI objects (add 'GDI Objects' to the 'Processes" TAB of Task Manager).
The program initiates with 49 GDI objects. It goes between 49-51 during the entire life of the program it starts at 900k and crashes at 1200k which is really small usage compared to the rest of the applications runnuing. CPU usage spikes to 100% before the crash though so maybe i am overloading the graphics card?
GetLastError() returns an int is there a way to output this to the debugger so I can check this value?
I guess it would be easier for you to know what i am not understanding if i just post the code. Could only upload 5 files so the vectoredit.h is only declarations of the CPP functions and the resource file looks like.
Code:
#include <resource.h>
IDB_SNAKEHEAD BITMAP "snakehead.bmp"
IDB_SNAKEHEADD BITMAP "snakeheadd.bmp"
IDB_SNAKEHEADU BITMAP "snakeheadu.bmp"
IDB_SNAKEHEADL BITMAP "snakeheadl.bmp"
IDB_SHMASK BITMAP "shmask.bmp"
IDB_SHMASKD BITMAP "shmaskd.bmp"
IDB_SHMASKU BITMAP "shmasku.bmp"
IDB_SHMASKL BITMAP "shmaskl.bmp"
IDB_MMASK BITMAP "mmask.bmp"
IDB_MOUSE BITMAP "mouse.bmp"
IDB_SBODY BITMAP "sbody.bmp"
IDB_SBMASK BITMAP "sbmask.bmp"
IDR_MYMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New Game", ID_FILE_NEWGAME
MENUITEM "&Change Difficulty", ID_FILE_CHANGEDIFFICULTY
MENUITEM "&View Achievements", ID_FILE_VIEWACHIEVEMENTS
MENUITEM "E&xit", ID_FILE_EXIT
END
END
The snake.cpp has all the drawing functions which is where the glitch is coming from i am guessing.