S
sxdinfo
Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个小工具,只是想抓取屏幕某个点的颜色,使用如下的代码,现发现在某些游戏中抓色时,移动鼠标,在颜色显示框中颜色的值和0交替显示,但是鼠标一停,就显示为0,不知道为什么,请各位高手帮忙看看,这段代码需要怎么改进啊?请指点一下,先谢谢了!
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
p: tpoint;
hhook: integer;
hd: thandle;
yanse: integer;
h:thandle;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled :=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
GetCursorPos(p);
edit1.Text:=inttostr(p.X );
edit2.text:=inttostr(p.Y );
h:=windowfrompoint(p);
edit4.Text:=inttostr(h);
hd:=getdc(0);
edit5.text:=inttostr(hd);
screentoclient(p);
yanse:=getpixel(hd,p.X,p.Y);
releasedc(0,hd);
edit3.Text:=inttostr(yanse);
shape1.Brush.Color:=yanse;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled :=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowPos(Form1.handle, HWND_TOPMOST,Form1.Left, Form1.Top, Form1.Width, Form1.Height,0);
end;
end.
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
p: tpoint;
hhook: integer;
hd: thandle;
yanse: integer;
h:thandle;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled :=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
GetCursorPos(p);
edit1.Text:=inttostr(p.X );
edit2.text:=inttostr(p.Y );
h:=windowfrompoint(p);
edit4.Text:=inttostr(h);
hd:=getdc(0);
edit5.text:=inttostr(hd);
screentoclient(p);
yanse:=getpixel(hd,p.X,p.Y);
releasedc(0,hd);
edit3.Text:=inttostr(yanse);
shape1.Brush.Color:=yanse;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled :=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowPos(Form1.handle, HWND_TOPMOST,Form1.Left, Form1.Top, Form1.Width, Form1.Height,0);
end;
end.