一个基于hook的屏幕涂鸭程序! (20分)

  • 主题发起人 主题发起人 jbas
  • 开始时间 开始时间
J

jbas

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是程序代码!不过有很多东西可以删除,各位可以自己删除。发表这个小东西,就当我为
dfw提供一点hook的资料,大家可别把它当垃圾了。:)
资源文件:
mycur cursor pen.cur //pen的资源文件定义
程序代码:

unit tymain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
GroupBox1: TGroupBox;
GroupBox3: TGroupBox;
SpeedButton3: TSpeedButton;
Panel1: TPanel;
Image1: TImage;
Panel2: TPanel;
Panel3: TPanel;
SpeedButton4: TSpeedButton;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure Image1DblClick(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Panel2DblClick(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure Panel5Click(Sender: TObject);
procedure Panel6Click(Sender: TObject);
procedure Panel7Click(Sender: TObject);
procedure Panel8Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
pencolor:tcolor;
mycanvas:tcanvas;
screendc:hdc;
pensize,hook,mm:integer;
can:boolean=false;
implementation
{$R *.dfm}
{$R mycursor.res}
function hookproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;
var
evtmsg:teventmsg;
begin
evtmsg:=peventmsg(lparam)^;
if evtmsg.message=WM_LBUTTONDOWN then
begin
can:=true;
mycanvas.moveto(mouse.CursorPos.X,mouse.CursorPos.Y);
end;
if evtmsg.message=WM_LBUTTONUP then
can:=false;
if can=true then
begin
if evtmsg.message=WM_MOUSEMOVE then
begin
with mycanvasdo
begin
Pen.Color:=form1.Panel1.Color;
lineto(mouse.CursorPos.X,mouse.CursorPos.Y);
end;
end;
end;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
screendc:=getdc(0);
mycanvas:=tcanvas.Create;
mycanvas.Handle:=screendc;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
InvalidateRect(0, nil, true);
//屏幕刷新
close;
end;

procedure TForm1.Image1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
pencolor:=image1.Picture.Bitmap.Canvas.Pixels[X,Y];
panel3.Color:=pencolor;
end;

procedure TForm1.Image1DblClick(Sender: TObject);
var
colordial:tcolordialog;
begin
colordial:=tcolordialog.Create(self);
colordial.Color:=pencolor;
colordial.Execute;
panel2.Color:=colordial.Color;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
var
scr:hicon;
begin
panel2.SetFocus;
scr:=loadcursor(hinstance,'mycur');
setsystemcursor(scr,ocr_normal);
//改变系统的鼠标图标
mycanvas.Pen.Color:=panel1.Color;
hook:=setwindowshookex(WH_JOURNALRECORD,hookproc,hinstance,0);
//安装钩子
end;

procedure TForm1.Panel2DblClick(Sender: TObject);
var
mycolor:tcolordialog;
begin
mycolor:=tcolordialog.Create(self);
mycolor.Color:=panel2.Color;
mycolor.Execute;
panel2.Color:=mycolor.Color;
end;


procedure TForm1.Image1Click(Sender: TObject);
begin
panel2.Color:=panel3.Color;
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
systemparametersinfo(spi_setcursors,0,nil,spif_sendchange);
//恢复系统的鼠标图标
unhookwindowshookex(hook);//撤销钩子
end;

procedure TForm1.Panel5Click(Sender: TObject);
begin
pensize:=panel5.Height;
if panel5.BorderStyle=bssingle then
begin
panel5.BorderStyle:=bsnone;
panel5.BevelInner:=bvnone;
panel5.BevelOuter:=bvnone;
end
else
begin
panel5.BorderStyle:=bssingle;
panel5.BevelInner:=bvlowered;
panel5.BevelOuter:=bvraised;
end;
end;

procedure TForm1.Panel6Click(Sender: TObject);
begin
pensize:=panel6.Height;
if panel6.BorderStyle=bssingle then
begin
panel6.BorderStyle:=bsnone;
panel6.BevelInner:=bvnone;
panel6.BevelOuter:=bvnone;
end
else
begin
panel6.BorderStyle:=bssingle;
panel6.BevelInner:=bvlowered;
panel6.BevelOuter:=bvraised;
end;
end;

procedure TForm1.Panel7Click(Sender: TObject);
begin
pensize:=panel7.Height;
if panel7.BorderStyle=bssingle then
begin
panel7.BorderStyle:=bsnone;
panel7.BevelInner:=bvnone;
panel7.BevelOuter:=bvnone;
end
else
begin
panel7.BorderStyle:=bssingle;
panel7.BevelInner:=bvlowered;
panel7.BevelOuter:=bvraised;
end;
end;

procedure TForm1.Panel8Click(Sender: TObject);
begin
pensize:=panel8.Height;
if panel8.BorderStyle=bssingle then
begin
panel8.BorderStyle:=bsnone;
panel8.BevelInner:=bvnone;
panel8.BevelOuter:=bvnone;
end
else
begin
panel8.BorderStyle:=bssingle;
panel8.BevelInner:=bvlowered;
panel8.BevelOuter:=bvraised;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
screendc:=getdc(0);
mycanvas:=tcanvas.Create;
mycanvas.Handle:=screendc;
end;
end.
可以在vcd播放的画面上画东西,挺有趣的。
 
呵呵,多谢。正在看有关问题。收藏~~
 
好。。。[:D]
 
多人接受答案了。
 
可否将完整的代码 e-mail 给我
thanks
 
收到,谢谢!
 
太好了,jbas,也给我一份好吗?yb79528@21cn.com
 
jbas,也给我一份好吗?
liuyj@cbn.com.cn
 
请给我一份:yangming_ok@163.net
十分感谢!
 
to jbas:
请问下,你的这个程序当在Image控件的图片中画图后,画的线条是否能和原图片一起保存为
一张新的图片?
 
我也想要一份源代码,请大哥给小弟发一份。
yzrlz@elong.com
 
to cloud_scorpion,
这个只是在屏幕上画东西,所以不能对image起作用,如果要起作用只能对image画东西。
如先取得image的dc,在画东西,保存。
to rlz,
sorry,我现在毕业了,也不搞电脑工作,连电脑都卖了,所以没那个东西,你把上面的代码
打上去吧,还可以去掉好多东西。
 
to jbas:
如何取得image的dc?在什么地方取?(在你的程序中)
 
我做了一个hook IE 的 .dll 文件,但当捕捉到ie事件时提示一些信息,但是任务栏上也出现了.dll 的消息,让窗体不出现在任务栏上可以用SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);有什么办法也让.dll文件运行时不在任务栏上提示任何信息。
 
后退
顶部