Click to See Complete Forum and Search --> : Ways Around GDI Resource Limits?


David Swigger
April 2nd, 1999, 11:56 AM
Hello All,

I have created some pretty graphic intensive controls.. They all use CBitmap for holding their
images..I am having a problem with this because
it eats up the GDI resources.. Heres my question/s
a. Is there a way to store a Bitmap(in memory) that I can draw to the screen that does not take up GDI resources..
b. Is there any way to expand the available GDI resources in Windows95/98?

Thanks for any help!

Regards

David Swigger

Please don't tell me it's impossible. That just means I have to proove it...

Fabian
April 2nd, 1999, 04:41 PM
To solve the resources leaking, you should delete the GDI object after you finish to used it. Take a look to

CGdiObject::DeleteObject()

or

BOOL DeleteObject(
HGDIOBJ hObject // handle to graphic object
);

Good luck

Fabian

David Swigger
April 2nd, 1999, 10:49 PM
Sorry, Im not talking about memory or GDI leaks,
Im saying that the amount of Objects that I am
using is taking up too much of the GDI..Im using
a ton of CBitmaps..
Sorry for the Confusion..

Regards

David

Please don't tell me it's impossible. That just means I have to proove it...

Todd Brannam
April 8th, 1999, 11:35 AM
There are two ways to approach this problem.

The easiest way, is to NOT keep all of your CBitmaps in memory. Dispose of them after they have been drawn, reload them as neccessary. You can reduce any performace loss by creating a type of caching mechanism to keep frequently drawn CBitmaps in memory.

The harder method would be to NOT use CBitmaps at all, instead using DIB's. Using DIB's will not use GDI, since a DIB is using memory from HEAP. With DIB's you will be responsible for making sure that the DIB color depth is less than or equal to the screen's color depth (for Blting performace) as well as color mapping performance issues. (Read Nigel Thompson's book on Animation Techniques in Win32 (MSPRESS)). Be sure to read up on 'identity palettes' to make sure your 256 color mode performance is optimal.

The first technique is a quicker fix, but if done right the second method is much better.

Regards,
Todd

mdbuck
April 8th, 1999, 10:23 PM
Why don't you store your images in an image list?

April 30th, 1999, 01:27 PM
There are a few things you can do...but it will be at the expense of performance. Not keeping all of the bitmaps in memory was a good suggestion - try it.

Also, encapsulate resources in braaces to force them in and out of scope. This is very helpful in looping code when a function is called many times.

Example:

void YourClass::Draw(CDC* pDC)
{
{
CDC tempDC(this);
DoABunchOfStuff( &tempDC);
pDC->BitBlt( tempDC, blah, blah );
} //close this brace if you no longer need tempDC
//since tempDC went out of scope it is not hogging
//up resources%3