First,
you are loosing GDI mem in DrawPieces()
Try this
Code:
void DrawPieces(HDC hdcWindow)
{
HDC hdcMemory;
HBITMAP hSysBMP;
hdcMemory = CreateCompatibleDC(hdcWindow);
hSysBMP=SelectObject(hdcMemory, XMask);
BitBlt(hdcWindow, xpos, 20, bmXPiece.bmWidth, bmXPiece.bmHeight, hdcMemory, 0, 0, SRCAND);
//this one will release XMask, I assume it is global
SelectObject(hdcMemory, XPiece);
BitBlt(hdcWindow, xpos, 20, bmXPiece.bmWidth, bmXPiece.bmHeight, hdcMemory, 0, 0, SRCPAINT);
//put the HDC back EXACTLY as you created it
SelectObject(hdcMemory,hSysBMP);
DeleteDC(hdcMemory);
}
When you / the user enters a new location for the BMP what do you do?
Do you call for a paint msg?
This is done with
InvalidateRect() or UpdateWindow()
Without this how will the app know that you want it to redraw the screen?
Use InvalidateRect() if you know the area to repaint (ie the dialogs client rect would be my choice, use GetClientRect() to find it)
Call the paint as soon as you have a NEW valid location.
//edit
On another point.
It is best to do as little as possible in the Paint function. It would be better to draw to a temp HDC and then after all the drawing is done, in this case the BMP is moved, copy this temp HDC to your hdcWindow. Then call for the paint.
The idea is all screen updates are quick (the OS may call a paint). None happen half way thru your drawing.
After you fix this problem,
Try a search here on FRAMEBUFFER's or look for 'help loading BMP's' ect
//end edit