Hook 鼠标消息拦截 不动鼠标,为什么总是拦截到鼠标消息?请高手指点迷津!(100)

  • 主题发起人 主题发起人 qhide
  • 开始时间 开始时间
Q

qhide

Unregistered / Unconfirmed
GUEST, unregistred user!
不动鼠标,为什么总是拦截到鼠标消息?请高手指点迷津!源代码如下:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; hHook: Integer;implementation{$R *.dfm}function HookProc(iCode: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;var PEvt: ^EVENTMSG;begin pEvt := Pointer(DWord(lParam)); if pEvt.message = WM_KEYDOWN then begin form1.Edit1.Text:=timetostr(time); end; if pEvt.message = WM_mousemove then begin form1.Edit1.Text:=timetostr(time); end;end;procedure TForm1.Button1Click(Sender: TObject);begin hHook := SetwindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0); Button2.Enabled := True; Button1.Enabled := False;end;procedure TForm1.Button2Click(Sender: TObject);begin UnHookWindowsHookEx(hHook); hHook := 0; Button1.Enabled := True; Button2.Enabled := False;end;end.
 
后退
顶部