Link to home
Start Free TrialLog in
Avatar of Steak23
Steak23

asked on

VB Error 480 - Can't create autoredraw image

Hi everybody!

I've got a program witch create Image box controls.  From the first control on my form (PicPreview(0)), my program create others images box control from the first one.

When I reach a certain level, my program stop working telling me that he can't create an autoredraw image.  I know this mean that there's no memory left to create others image control boxes.

Is there a way to validate how many memory left for the create of a new control at run-time?

Hopes you'll be able to help me... If anyone want any precision, please, ask!

Thanks
Steak
Avatar of mdougan
mdougan
Flag of United States of America image

You are probably running out of GDI memory (specifically).  There is an API that will tell you how much is in use, and how much is available, but off the top of my head I can't remember which one... GetMemory...something.

Anyway, if you have the VB Samples installed, look for a project named CallDlls.  This project calls these Windows APIs to tell you about the status of your different areas of memory.

Alternatively, I think that there is a SystemInfo control in VB now, that you can also use to get this information.  Check under Project|Components for Microsoft SysInfo control, add it to your form and see what it can tell you.
Avatar of nichia
nichia

1) You could trap this error, and abort loading any new PictureBox controls. Or,

2) Set the Autoredraw property False
Avatar of Steak23

ASKER

mdougan,

I've tried to find something that could tell me how many GDI memory left, but it seems that System Info doesn't provide any information on that.

You told me about an API function that could tell me how much GDI memory left... This gives standard memory, but I can't see anything about GDI ressources.

I also took a look at the system_info, but it doesn't give what I need....
Hopes you have other ideas....

Nichia,
1) I can't do this.  I've got to print all the picture box... Thoses contains reports pages which are all needed by the user.
2) I can't set autoredraw to false, my graphics stop displaying...  (Thoses Pictures box are considered like reports pages, so, if I display a page, the others are simply hidden behind....)

Thanks for you help guys!  But it doesn't resolve my problem!  

Hopes you have other ideas!
Can you limit the report to only 2 pages at a time?  This is how MS deals with the problem (Print preview from Word).

Another solution would be to generate the images on-the-fly in the Paint event of each PictureBox.  This way, the Autoredraw property can be set to False, and the pictures will still appear when they are displayed on top.
Avatar of Steak23

ASKER

Nichia,

   about the to pages at a time, I only get one page by picture box, so, if my report is 100 pages long, it will generate 100 pictures box controls....
But I'll take a look at it...

The generation on the fly couldn't be used 'cause it take about an hour and half to extract all the data needed by the complete report.  But your answer gives me an idea:  What about an image collection that could store thoses pictures?  Is this control be able to handle as many as 100 pictures and more?

I'm gonna try this when I'll be at the office.  If anyone has an advice about this, tell me, it could help a lot!

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steak23

ASKER

Hi!
I give the points to mdougan, since he found that the problem was coming from the GDI.

It hadn't fixed my problem, but it helped to elaborate a new solution.

We'll be using files (bitmaps) to store the pages that get printed by the program.  So, as soon as a page is requested, we'll be able to load them from disk.

I had several people that told me that I should split the report, fetch less data before the error comes... but I can't uses thoses answer 'cause I had to print all of the pages that the report print.

So, by showing me that the memory was the main problem, it helped me to produce this fix.

Thanks to all for the help!
Steak
Another answer is to increase the SessionViewSize.
This site explains why:
http://blogs.msdn.com/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx

And the specific change I made to solve this problem fo rmyself was to change the following value from 30 to 80.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\SessionViewSize