?
Solved

Canvas

Posted on 2000-04-05
19
Medium Priority
?
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 600 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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