BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Device contexts ... just how long are they valid for?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Graham Thompson
Guest





PostPosted: Thu Jul 28, 2005 9:33 am    Post subject: Device contexts ... just how long are they valid for? Reply with quote



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





PostPosted: Thu Jul 28, 2005 5:33 pm    Post subject: Re: Device contexts ... just how long are they valid for? Reply with quote



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





PostPosted: Fri Jul 29, 2005 10:04 am    Post subject: Re: Device contexts ... just how long are they valid for? Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.