-
Lots of bitmaps
Hi. I am really new to this kind of programming, windows programming I mean.
Anyway, I made a program yesterday which is an empty window and has a bitmap in it. When the user moves the keys around, the picture moves along with them. Now, here's the problem:
I want it so that there would be two pictures in the program, and that they could both move. The moving thing should be fine, but i don't know how to put two pictures in the screen, well I do, but I don't know how to see both the picture on on the same window. If I put in a second picture the way I put in the first one, the first one dissappears, and I can't se it. I reckon it must be something to do with the function deleting the entire contents, and then re-printing them, but I really don't know. I have done lots of MSDN searching and whatnot, but i can't see anything that could help. I think it's commented enough ... I hope.
Anyways, here's the code (attached), and if anyone can help me, it would be greatly appreciated!!
-
MFC or pure Win32?
For MFC you need to override the OnPaint() and create a memory DC along with a memory CBitmap.
Code:
void SomeWindow::OnPaint(void)
{
CPaintDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(&rect);
CBitmap memBitmap;
memBitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
CBitmap *pPrevBitmap=memDC.SelectObject(&memBitmap);
//Draw to memDC now
....
....
//Blit final result to dc
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
memDC.SelectObject(pPrevBitmap);
}
This is the equivalent of double buffering in MFC code. Check the code because the SelectObject's don't look quite right. If you leak GDI objects here, those lines are the culprit.