Discussion:
Drawing lines
(too old to reply)
battles
2010-11-07 16:58:27 UTC
Permalink
I am using the procedure below to draw a line on the screen. How do
I increase the pen width? Canvas isn't working.
Also, is there any way to force the line to stay there? As it is
now, it erases whenever you drag the mouse over it. What I am trying
to do is create a program that overlays a nautical chart in a browser
whereby you can plot degrees between way points. Thanks.

var DC, PanDC: HDC; x, y: Integer; bmp: HbitMap;
begin
dc := GetDc(0);
Canvas.Pen.Width := 7;

MoveToEx(Dc, Form1.Left + 100, Form1.Top + 100, nil);
LineTo(Dc, 300, 300);

ReleaseDC(0, DC);
end;
Jamie
2010-11-07 19:26:36 UTC
Permalink
Post by battles
I am using the procedure below to draw a line on the screen. How do
I increase the pen width? Canvas isn't working.
Also, is there any way to force the line to stay there? As it is
now, it erases whenever you drag the mouse over it. What I am trying
to do is create a program that overlays a nautical chart in a browser
whereby you can plot degrees between way points. Thanks.
var DC, PanDC: HDC; x, y: Integer; bmp: HbitMap;
begin
dc := GetDc(0);
Canvas.Pen.Width := 7;
MoveToEx(Dc, Form1.Left + 100, Form1.Top + 100, nil);
LineTo(Dc, 300, 300);
ReleaseDC(0, DC);
end;
You are going to have a hard time with that how ever, I can offer
some suggestions because i've done this kind of hacking before..

First of all, use a Timage to contain your drawing, it has a bitmap
object in it along with a canvas ofcourse..

Place it on a borderless form... First make a copy of what is on the
browser and copy it to the Timage. Now you have the browser screen
in your timage, from there you enable the form and position it over the
browser screen, you draw on your Timage.

Or, you could just simply move the portion you want from the browser
screen to your timage and manage the drawing away from the browser..
Lets say for example a little pop up looking thing that shows just
beside the image on the browser..

As far as the line size..
MyTimage.Canvas.Pen.Width := ?
What you did there has nothing to do with the destination canvas..
But here is something that may help you.

MyCanvas :Tcanvas.

MyCanvas := TCanvas.Create;
MyCanvas.Handle := GetDC(0);
and from there. you use the MyCanvas..

Also..

DC := GetDC(GetDeskTopWindow); is what you should be using...


etc...
battles
2010-11-07 19:05:24 UTC
Permalink
Post by Jamie
Post by battles
I am using the procedure below to draw a line on the screen. How do
I increase the pen width? Canvas isn't working.
Also, is there any way to force the line to stay there? As it is
now, it erases whenever you drag the mouse over it. What I am trying
to do is create a program that overlays a nautical chart in a browser
whereby you can plot degrees between way points. Thanks.
var DC, PanDC: HDC; x, y: Integer; bmp: HbitMap;
begin
dc := GetDc(0);
Canvas.Pen.Width := 7;
MoveToEx(Dc, Form1.Left + 100, Form1.Top + 100, nil);
LineTo(Dc, 300, 300);
ReleaseDC(0, DC);
end;
You are going to have a hard time with that how ever, I can offer
some suggestions because i've done this kind of hacking before..
First of all, use a Timage to contain your drawing, it has a bitmap
object in it along with a canvas ofcourse..
Place it on a borderless form... First make a copy of what is on the
browser and copy it to the Timage. Now you have the browser screen
in your timage, from there you enable the form and position it over the
browser screen, you draw on your Timage.
Or, you could just simply move the portion you want from the browser
screen to your timage and manage the drawing away from the browser..
Lets say for example a little pop up looking thing that shows just
beside the image on the browser..
As far as the line size..
MyTimage.Canvas.Pen.Width := ?
What you did there has nothing to do with the destination canvas..
But here is something that may help you.
MyCanvas :Tcanvas.
MyCanvas := TCanvas.Create;
MyCanvas.Handle := GetDC(0);
and from there. you use the MyCanvas..
Also..
DC := GetDC(GetDeskTopWindow); is what you should be using...
etc...
Thanks. This has given me a better idea of what I am looking to do.
I was messing with a transparent form, trying to draw a new
transparency with a line therein, but that wasn't giving any success.
I was getting a bad mental strain from the effort. I have a program
that (I thought) was drawing lines on the screen on top of its
invisible form. However, it is actually probably copying the image
into its own program and doing the drawing on the copy as you
suggest. Now all I need is to find how to draw a line in the bitmap
on the copy. Possibly draw it on a transparent second bitmap.
a***@aol.com
2010-11-09 08:23:31 UTC
Permalink
I think you should draw your line in the form's OnPaint event handler.
Then your line would be redrawn when a repaint of the form is called
by Windows.

Alan Lloyd
battles
2010-11-09 13:39:50 UTC
Permalink
Post by a***@aol.com
I think you should draw your line in the form's OnPaint event handler.
Then your line would be redrawn when a repaint of the form is called
by Windows.
Alan Lloyd
Thanks. Always glad to see you are still here, as well as some
other old timers.

Loading...