下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 在应用程序中跟踪mouse的坐标 第一步,建一dll,delphi中new-dll save as getkey library getkey; usessysutils,windows,hookmain in hookmain.pas; exportsopengetkeyhook,closegetkeyhook,getpublicp; beginnexthook := 0;procsaveexit := exitproc;dllproc := dllmain;exitproc := hookexit;dllmain(dll_process_attach);end. 第二步,建一unit ,
2、hook main。关键在于createfilemapping 和 消息 wm_ncmousemove, wm_mousemove: unit hookmain; interfaceuses windows, messages, dialogs, sysutils; /type databuf = array 1.2 of dword;type mydata=recorddata1:array 1.2 of dword;data2:tmousehookstruct;end;var hobject : thandle;pmem : pointer;nexthook: hhook;procsave
3、exit: pointer; function hookhandler(icode: integer; wparam: wparam; lparam: lparam): lresult; stdcall; export;function opengetkeyhook(sender : hwnd;messageid : word) : bool; export;function closegetkeyhook: bool; export;function getpublicp : pointer;stdcall; export;procedure dllmain(dwreason:dword);
4、 far;procedure hookexit; far; implementation procedure unmapmem;beginif assigned(pmem) thenbeginunmapviewoffile(pmem);pmem := nilend;end; procedure mapmem;beginhobject := createfilemapping($ffffffff,nil,page_readwrite,0,$ffff,pchar(_iobuffer);if hobject = 0 then raise exception.create(创建公用数据的buffer不
5、成? ;pmem := mapviewoffile(hobject,file_map_write,0,0,sizeof(mydata);/ 1 or sizeof(databuf) ?/ 创建sizeof(databuf)的数据区if not assigned(pmem) thenbeginunmapmem;raise exception.create(创建公用数据的映射关系不成功!);end;end;procedure dllmain(dwreason:dword); far;begincase dwreason ofdll_process_attach :beginpmem := nil;
6、hobject := 0;mapmem; /以下的公有数据,如thwnd,tmessageid将直接使用本buf.end;dll_process_detach : unmapmem;dll_thread_attach,dll_thread_detach :; /缺省end;end; procedure hookexit; far;beginclosegetkeyhook;exitproc := procsaveexit;end; function getpublicp : pointer;export;begin /这里引出了公用数据区的指针,你可以在你的应用程序中自由操作它。但建议去掉此接口
7、。result := pmem;end; function hookhandler(icode: integer; wparam: wparam; lparam: lparam): lresult; stdcall; export;beginresult := 0;if icode $#60; 0then result := callnexthookex(nexthook, icode, wparam, lparam);/ this is probably closer to what you would want to do.case wparam ofwm_lbuttondown:begi
8、nend;wm_lbuttonup:beginend;wm_lbuttondblclk:beginend;wm_rbuttondown:beginmessagebeep(1);end;wm_rbuttonup:beginend;wm_rbuttondblclk:beginend;wm_mbuttondown:beginend;wm_mbuttonup:beginend;wm_mbuttondblclk:12beginend;wm_ncmousemove, wm_mousemove:beginmydata(pmem).data2:=pmousehookstruct(lparam);/ messa
9、gebeep(1);/sendmessage(databuf(pmem)1,databuf(pmem)2,wparam,lparam );sendmessage(mydata(pmem).data11,mydata(pmem).data12,wparam,integer(mydata(pmem).data2) );end;end; /发送消息end; function opengetkeyhook(sender : hwnd;messageid : word) : bool; export;beginresult := false;if nexthook $#60;$#62; 0 then e
10、xit; /已经安装了本钩子/ databuf(pmem)1 := sender; /填数据区/ databuf(pmem)2 := messageid; /填数据区mydata(pmem).data11:=sender;mydata(pmem).data12:=messageid; nexthook := setwindowshookex(wh_mouse, hookhandler, hinstance, 0);result := nexthook $#60;$#62; 0;end; function closegetkeyhook: bool; export;beginif nexthoo
11、k $#60;$#62; 0 thenbeginunhookwindowshookex(nexthook); /把钩子链链接到下一个钩子处理上.nexthook := 0;end;result := nexthook = 0;end; end. 第三步,测试dll,建一project。关键在于override wndproc unit unit1; interface useswindows, messages, sysutils, classes, graphics, controls, forms, dialogs,stdctrls, extctrls; typetform1 = clas
12、s(tform)uncapture: tbutton;capture: tbutton;exit: tbutton;panel1: tpanel;show: tlabel; label1: tlabel;counter: tlabel;procedure exitclick(sender: tobject);procedure uncaptureclick(sender: tobject);procedure captureclick(sender: tobject);private private declarations public public declarations procedu
13、re wndproc(var message: tmessage); override;end; varform1: tform1;var num : integer;const messageid = wm_user + 100;implementation $r *.dfmfunction opengetkeyhook(sender : hwnd;messageid : word) : bool; external getkey.dll;function closegetkeyhook: bool; external getkey.dll; procedure tform1.exitcli
14、ck(sender: tobject);beginclose;end; procedure tform1.uncaptureclick(sender: tobject);beginif closegetkeyhook then /showmessage(结束记录.);show.caption:=结束记录.;end; procedure tform1.captureclick(sender: tobject);begin/ if opengetkeyhook(self.handle,messageid) then showmessage(开始记录.); if opengetkeyhook(form1.handle,messageid) then/showmessage(开始记录.);show.caption:=开始记录.;num := 0;end; procedure tform1.wndproc(var message: tmessage);var x,y:integer;beginif message.msg = messageid thenbegin/ panel1.capt
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年青海省海南藏族自治州单招职业倾向性考试题库带答案详解(轻巧夺冠)
- 2026年黄河交通学院单招职业技能考试题库含答案详解(考试直接用)
- 2026年长沙民政职业技术学院单招职业技能考试题库附答案详解(突破训练)
- 2026年陕西警官职业学院单招职业适应性测试题库及完整答案详解
- 2026年陕西能源职业技术学院单招职业倾向性测试题库附参考答案详解(突破训练)
- 2026年陕西艺术职业学院单招职业技能考试题库完整参考答案详解
- 2026年青岛工程职业学院单招综合素质考试题库含答案详解(精练)
- 2025年扬州大学公开招聘教学科研和医务人员175 人备考题库(第二批)及答案详解一套
- 点心茶楼营销方案(3篇)
- 2026广东省农业科学院设施农业研究所招聘劳动合同制人员1人考试备考题库及答案解析
- 种植多肉教学课件
- 语文●全国Ⅰ卷丨2024年普通高等学校招生全国统一考试语文试卷及答案
- (高清版)DG∕TJ 08-2405-2022 水运工程装配式护岸结构技术标准
- 2025智能接地箱技术规范
- 抗癫痫发作药物联合使用中国专家共识2025
- 春天的秘密幼儿园教育
- 人工智能在档案管理中的应用与发展
- 《医学影像检查技术学》课件-足X线摄影
- 部队采购招标资料3篇
- 南京财经大学C语言期末(共六卷)含答案解析
- 2024年度中国协同办公平台行业研究报告
评论
0/150
提交评论