| 发表于:2007-08-28 11:08:06 楼主 |
unit unit1; interface uses windows, messages, sysutils, classes, graphics, controls, forms, dialogs, stdctrls; type tform1 = class(tform) button1: tbutton; button2: tbutton; button3: tbutton; procedure formcreate(sender: tobject); procedure button1click(sender: tobject); procedure button2click(sender: tobject); procedure button3click(sender: tobject); private { private declarations } public { public declarations } end; var form1: tform1; eventarr:array[0..1000]of eventmsg; eventlog:integer; playlog:integer; hhook,hplay:integer; bdelay:bool; implementation {$r *.dfm} function playproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall; begin result:=0; if icode < 0 then result := callnexthookex(hplay,icode,wparam,lparam) else if icode = hc_sysmodalon then // canplay:=0 else if icode = hc_sysmodaloff then // canplay:=1 else if (icode=hc_getnext) then begin if bdelay then begin bdelay:=false; result:=50; \\为什么这里的返回值是50? end; peventmsg(lparam)^:=eventarr[playlog]; end else if (icode = hc_skip)then begin bdelay := true; playlog:=playlog+1; end; if playlog> =eventlog then begin unhookwindowshookex(hplay); end; end; function hookproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall; begin // recok:=1; result:=0; if icode < 0 then result := callnexthookex(hhook,icode,wparam,lparam) \\icode有怎么多个参数,如何知道他传过来的是哪个参数,可能说的不太清楚,我也不太清楚怎么说只是要问当setwindowshookex要调用这个hookproc钩子函数,如何知道他传递过来的icode是什么值.是自动决定的吗? else if icode = hc_sysmodalon then // recok:=0 else if icode = hc_sysmodaloff then // recok:=1 else if (icode = hc_action) then begin eventarr[eventlog]:=peventmsg(lparam)^; eventlog:=eventlog+1; if eventlog> =1000 then begin unhookwindowshookex(hhook); end; end; end; procedure tform1.formcreate(sender: tobject); begin button2.enabled:=false; button3.enabled:=false; end; procedure tform1.button1click(sender: tobject); begin eventlog:=0; hhook:=setwindowshookex(wh_journalrecord,hookproc,hinstance,0); button2.enabled:=true; button1.enabled:=false; button3.enabled:=false; end; procedure tform1.button3click(sender: tobject); begin playlog:=0; hplay:=setwindowshookex(wh_journalplayback,playproc, hinstance,0); end; procedure tform1.button2click(sender: tobject); begin unhookwindowshookex(hhook); hhook:=0; button1.enabled:=true; button2.enabled:=false; button3.enabled:=true; end; end. 我提的问题都是上边注释提的问题,还有一个不懂.callnexthookex到底把钩子函数传递给谁.因为我看的几个钩子例子都只有一个钩子函数,callnexthookex到底把信息传递给谁了. |
|
|
|
|