GDI Blitting
I have, for my level editor (using MFC), a function that takes a CDC* as a parameter, to draw the enemies to the window. In the OnPaint function for my window (for the child view) I call this function, with the dc that came with the function as a parameter, but it''s not drawing. Is there some reason a cdc pointer can''t be passed to a function and still work?
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
February 05, 2000 02:51 AM
I don''t know a whole lot about MFC, but there are a couple of things that could be happening. One, the pointer to the CDC object is invalid, or two, the window is not being refreshed properly, for example, the window paint area is not being invalidated, or something. Sorry if that doesn''t help in any way.
I''m assuming you''re blitting a bitmap, in which case you can''t use the CDC that came in, as you can''t blit directly to the screen. You have to copy to a temporary compatible CDC and then blit that temporary CDC to your screen''s device context, like so:
CDC dcMemory;
CBitmap back;
back.LoadBitmap(IDB_BACK);
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(&back);
pDC->BitBlt(0, 0, 600, 400, &dcMemory, 0, 0, SRCCOPY);
Make sure you delete your temporary DC when you''re done, like so:
ReleaseDC(&dcMemory);
DeleteDC(dcMemory);
DeleteObject(back);
or you will have problems as you run out of device context space. I deleted my bitmap because I loaded it right there, but it''s also alright to load it elsewhere and store it.
HTH
-fel
CDC dcMemory;
CBitmap back;
back.LoadBitmap(IDB_BACK);
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(&back);
pDC->BitBlt(0, 0, 600, 400, &dcMemory, 0, 0, SRCCOPY);
Make sure you delete your temporary DC when you''re done, like so:
ReleaseDC(&dcMemory);
DeleteDC(dcMemory);
DeleteObject(back);
or you will have problems as you run out of device context space. I deleted my bitmap because I loaded it right there, but it''s also alright to load it elsewhere and store it.
HTH
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
I am creating a temperary DC to use for the image, with an HBITMAP (I didn't use CBitmap because I already knew how to use HBITMAP easily). And the way I'm blitting works for my level's tiles, just not for the enemies. Although I don't think I was deleting the temperary DCs after I made them... Shouldn't that be taken care of in the CDC destructor?
Edited by - Qoy on 2/6/00 2:28:51 AM
Edited by - Qoy on 2/6/00 2:28:51 AM
The weirdest thing is that the blitting in the EXACT same way works for the tiles... Do I need to explicitly delete the CDC?
I''ve stopped trusting the supposed OnIdle GDI cleanup, as it doesn''t seem to work half the time.
-fel
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement