Q
qhide
Unregistered / Unconfirmed
GUEST, unregistred user!
按Ctrl+Alt+Del后,钩子(DLL)失效!如果不按Ctrl+Alt+Del,一切都正常。不知问题出在哪里,请各路高手多多指点!源码如下:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;var Form1: TForm1; MousePos: TPoint; hNextHookProc:HHOOK;implementation{$R *.dfm}function KeyBHkHandle(iCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;//export; var pEvt:TEventMsg; Pos: TPoint;begin if (iCode<0) then begin Result:=CallNextHookEx(hNextHookProc,iCode,wParam,integer(lParam)); exit; end; if iCode=HC_ACTION then begin pEvt:=PEventMsg(lParam)^; if (pEvt.message=WM_MOUSemove) then begin GetCursorPos(Pos); if (Abs(MousePos.X-Pos.X)>0) or (Abs(MousePos.Y-Pos.Y)>0) then begin GetCursorPos(MousePos); form1.Edit1.Text:=timetostr(time); end; end else if (pEvt.message=WM_KEYDOWN) or (pEvt.message=WM_SYSKEYDOWN ) then begin form1.Edit1.Text:=timetostr(time); end; end; Result:=CallNextHookEx(hNextHookProc,iCode,wParam,integer(lParam));end;procedure TForm1.FormCreate(Sender: TObject);beginGetCursorPos(MousePos);if hNextHookProc=0 then hNextHookProc:=SetWindowsHookEx(WH_JOURNALRECORD,KeyBHkHandle,HInstance,0);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);beginif hNextHookProc<>0 then begin UnhookWindowsHookEx(hNextHookProc); hNextHookProc:=0; end;end;end.