如何在桌面上画一条直线!(20分)

W

wgjxnm

Unregistered / Unconfirmed
GUEST, unregistred user!
如果用DELPHI在桌面上画一条直线!
 
这样看看:

procedure TForm1.Button1Click(Sender: TObject);
var
c:Tcanvas;
begin
c:=Tcanvas.create;
c.handle:=getdc(0);
c.lineto(200,100);
c.free;
end;
 
怎么用鼠标移到某窗体,并获得这个窗体的句柄?
 
这就不知道了
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Timer1: TTimer;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
Label6: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure getmousehandle(sender:tpoint);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
var
rpos:tpoint;
begin
if boolean(getcursorpos(rpos)) then
getmousehandle(rpos);
end;

procedure tform1.getmousehandle(sender:tpoint);
var hwnd:thandle;
aname:array[0..255] of char;
gwlid,l:integer;
ss:pchar;
begin
label4.Caption:='X:'+inttostr(sender.x);
label5.Caption:='Y:'+inttostr(sender.y);
hwnd:=windowfrompoint(sender);
sendmessage(hwnd,WM_GETTEXTLENGTH,0,l);
inc(l);
getmem(ss,l);
sendmessage(hwnd,WM_GETTEXT,l,longint(lpstr(ss)));
memo1.Lines.clear;
if hwnd<>memo1.handle then
memo1.Lines.Append(string(ss));
freemem(ss,0);
label1.Caption:='Handle:'+inttostr(hwnd);
if boolean(getclassname(hwnd,aname,256)) then
label2.Caption:='Classname:'+string(aname)
else
label2.Caption:='classname not found!';
gwlid:=getwindowlong(hwnd,GWL_ID);
label3.Caption:='ID:'+inttostr(gwlid);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.Interval:=50;
end;

end.
 
顶部