 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Graham Thompson Guest
|
Posted: Thu Jul 28, 2005 9:33 am Post subject: Device contexts ... just how long are they valid for? |
|
|
Hi all,
I'm working on a legacy application that does a lot of drawing to the
screen; all the functions take a handle to a device context (HDC) for their
drawing. I'm implementing off-screen drawing at the moment, and I've
implemented a 'painter' class that manages the off-screen bitmap and device
context - one instance per window.
I'm currently providing the application with my 'memory' DC in two cases -
when writing to the off-screen bitmap (i.e. drawing), and reading (i.e.
during the window's WM_PAINT handler).
Traditional API coding would suggest that I CreateCompatibleDC() and then
select my bitmap into it in both of these cases, but I've noticed that I can
CreateCompatibleDC() once, then in each of the read and write methods,
select the memory bitmap into it and return a handle to it. So, I only
create the off-screen DC when the window is created, or its size changes.
This DC then lasts the lifetime of the 'painter' instance... and its drawing
just fine.
Is this illegal? Is calling CreateCompatibleDC() such an inexpensive
function that I should create and destroy the memory DC for each read and
write call? Or, is it OK to use the same DC throughout the lifetime of the
'painter' instance?
Thanks for any advice...
GT
|
|
| Back to top |
|
 |
Damon Chandler (TeamB) Guest
|
Posted: Thu Jul 28, 2005 5:33 pm Post subject: Re: Device contexts ... just how long are they valid for? |
|
|
Hi Graham,
What you're doing sounds fine. Memory DCs, as opposed to common
display DCs, don't come the GDI's device context cache. In fact,
because the "memory" of a memory DC is necessarily a bitmap, you can
leave your bitmap selected into the DC for as long as you want; just
don't try to select the bitmap into multiple memory DCs. You can also
create a bitmap that's optimal for the current screen settings, which
significantly reduces the amount of time required to draw the bitmap to
the screen; see the article "Display-optimal DIB section bitmaps" in
this issue...
http://bcbjournal.com/get_doc.php?art=subscribers/articles/pdfs/may_2002.pdf
Just be sure to handle the WM_DISPLAYCHANGE message to update your
bitmap accordingly.
Good luck,
Damon
Graham Thompson wrote:
| Quote: | Is this illegal? Is calling CreateCompatibleDC() such an inexpensive
function that I should create and destroy the memory DC for each read and
write call? Or, is it OK to use the same DC throughout the lifetime of the
'painter' instance?
|
|
|
| Back to top |
|
 |
Graham Thompson Guest
|
Posted: Fri Jul 29, 2005 10:04 am Post subject: Re: Device contexts ... just how long are they valid for? |
|
|
"Damon Chandler (TeamB)" <editor (AT) _REMOVE_THIS_SPAM_GUARD_bcbjournal (DOT) com>
wrote in message news:42e916ef (AT) newsgroups (DOT) borland.com...
: Hi Graham,
: What you're doing sounds fine. <snip>
Phew...
: Just be sure to handle the WM_DISPLAYCHANGE message to update your
: bitmap accordingly.
Will do ... thanks once again for your help, Damon!
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|