Solved

Canvas

Posted on 2000-04-05
19
482 Views
Last Modified: 2010-04-04
Hi!
Sometimes I get a stupid mistake: "Canvas doesn't allow drawing". Usually it happens if another window covers a part of my window (but not always). What I do: I have some controls, on the canvas of which I perform some drawing. Does anybody know what to do?

Thanks.
0
Comment
Question by:shtern
  • 8
  • 3
  • 2
  • +6
19 Comments
 
LVL 2

Expert Comment

by:kubeerja
ID: 2687287
can u show part of your code
0
 

Author Comment

by:shtern
ID: 2687315
It's really long. There are a couple of self-made components, which perform a lot of drawing. It's a simple drawing on canvas: Canvas.Draw, BitBlt and so on.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2687562
There are a few possible reasons for this.

1. The canvas on which you are trying to draw has been locked.

2. The handle to the canvas which you are drawing on (or attempting to anyway) is not valid.

 if you are moving things around on the form and using screen coordinates for the drawing, you might be actually trying to draw unto something which does not allow it. (such as a form's caption bar).
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2688494
listenning
0
 
LVL 1

Expert Comment

by:nrico
ID: 2689152
You can eliminate (2) if you use Form.Canvas.Handle.
0
 
LVL 1

Expert Comment

by:sageryd
ID: 2689343
Try using a TImage instead of painting directly on the form canvas. Might work better.

--johan
0
 

Author Comment

by:shtern
ID: 2689377
I draw direct on the control's canvas, and use the coordinates inside of it, so it can't be the form's caption. Using TImage could be OK, but where is the difference? I have created my own component, something like TTreeView, but with other possibilities, and the drawing I perform is the drawing of nodes on it. Should I use TImage as background?

Except, it happens only if another window (e.g. Explorer) has covered a part of my window for a while. As my window becomes active again, this error occurs, but not always.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2689432
Is it possible your try drawing in control was created, but not inserted in Z-order? I mean:

C:=TMyControl.Create(Self);
// you can't draw before next operator is executed.
InsertControl(C);
// now drawing available.

-----
Igor.
0
 

Author Comment

by:shtern
ID: 2689470
It's not when the program starts. I can work any time with it, and then it happens. This control is on the main form, and it is always open.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ITugay
ID: 2689497
When you move some form over your component, it may force drawing of your component. Do you have the message at that moment?
----
Igor.
0
 

Expert Comment

by:MaximW
ID: 2711947
It happens if you use a lot of graphics and your system GDI resources are low(=0).Optimizing of open DCs & bitmaps should help.
0
 

Author Comment

by:shtern
ID: 2712787
MaximW, could you please tell me more about it. Yes, I use graphic, but not so much, and it happens on many computers with different resources. What do you mean with optimizing?
0
 

Expert Comment

by:MaximW
ID: 2720638
If the problem is running out of GDI resources... try to look up
b : TBitmap;
b.Dormant;
b.ReleaseImage;

P.S. Sorry for so unclear advises, but i have the same problem to solve:).
0
 

Author Comment

by:shtern
ID: 2720727
I don't understand why is it running out of resources. I have just some bitmaps (two or three) which I draw with Canvas.Draw as a Background and some TImage's, no more. But maybe it's a case.

But I haven't understood your last advise: where should I use it?

Sorry for such a question, but I've read in delphi help about it, and understood practically nothing.
0
 

Expert Comment

by:MaximW
ID: 2722251
Hi
 regarding
 .Dormant
 .FreeImage

 as far as I know,  for  every TBitmap or TImage object you open, GDI locks an entry for HBITMAP(bmp handle) in the GDI table. The more bitmap objects you have open the less free entries remain.
So ,if you use a bitmap for drawing purpose only, something like this

 mb:= TBitmap.Create;
 mb.LoadFromResources(...
 .Canvas.Draw (x,y,mb);

and you need TBitmap object(not the image) itself for the future use, makes sense the following:
mb:= TBitmap.Create;
 mb.LoadFromResources(...
 .Canvas.Draw (x,y,mb);
 mb.Dormant;
 mb.FreeImage;
//it will release the GDI entry

even if you place it in the loop of ...200, you will have 200 TBitmap objects and the same level of GDI res. as it  has been before the loop.
As I have seen in Delphi help and some Delphi books, only .Dormant must do that keeping your image in memory stream instead of open image, and free GDI res , but it doesn't:-). Maybe i don't understand it good enough.
0
 

Author Comment

by:shtern
ID: 2723466
Can you also explain me what does it change (except freeing resources)? Maybe, the quality will be not so good or what?
0
 

Author Comment

by:shtern
ID: 2730774
Adjusted points from 100 to 200
0
 
LVL 1

Accepted Solution

by:
saulite earned 200 total points
ID: 2787813
Before draw on window, bring it to front. Do this every time, before drawing
0
 

Author Comment

by:shtern
ID: 2789121
Could you, please, be more exact? I have my program running. Then I run, e.g., Explorer. As I then go to my program again (e.g. Alt-Tab), this error happens. But (!) not always. Maybe it's really something with resources?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now