主要是想拦截鼠标左键的点击,在点击三次后释放钩子,如果不在ACTTEST中加入SHOWMESSAGE(‘LLLL’);时就没什么问题,加入后,如果在DELPHI中调试,连DELPHI都会很快的跳出,如果单纯的运行的话好象就跳不出钩子程序。
是不是钩子程序中的操作有什么限制?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PointSite=record
X:integer;
Y:integer;
end; TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure ActTest;
{ Public declarations }
end;var
Form1: TForm1;
hHook:Integer;
ClickCount:integer;
SitePos:^tagMOUSEHOOKSTRUCT;implementation{$R *.dfm}Function MouseC(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
Result:=0;
if iCode<0 then
Result:=CallNextHookEx(Hhook,iCode,wParam,lParam)
else
begin
if WParam = WM_LButtonDown then begin
Inc(ClickCount);
SitePos:=Ptr(LParam);
Form1.ActTest; end;
if ClickCount>2 then begin
UNHookWindowsHookEx(Hhook);
Hhook:=0;
ClickCount:=0;
end;
end;
end;procedure TForm1.ActTest;
begin
Form1.Memo1.Lines.Append('X:='+inttostr(SitePos^.pt.X)+
' '+'Y:='+inttostr(SitePos^.pt.Y)); SHOWMESSAGE('LLLLL');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ClickCount:=0;
//建立一个钩子
Hhook:=SetWindowsHookEx(WH_Mouse,MouseC,HInstance,0);
end;end.
是不是钩子程序中的操作有什么限制?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PointSite=record
X:integer;
Y:integer;
end; TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure ActTest;
{ Public declarations }
end;var
Form1: TForm1;
hHook:Integer;
ClickCount:integer;
SitePos:^tagMOUSEHOOKSTRUCT;implementation{$R *.dfm}Function MouseC(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
Result:=0;
if iCode<0 then
Result:=CallNextHookEx(Hhook,iCode,wParam,lParam)
else
begin
if WParam = WM_LButtonDown then begin
Inc(ClickCount);
SitePos:=Ptr(LParam);
Form1.ActTest; end;
if ClickCount>2 then begin
UNHookWindowsHookEx(Hhook);
Hhook:=0;
ClickCount:=0;
end;
end;
end;procedure TForm1.ActTest;
begin
Form1.Memo1.Lines.Append('X:='+inttostr(SitePos^.pt.X)+
' '+'Y:='+inttostr(SitePos^.pt.Y)); SHOWMESSAGE('LLLLL');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ClickCount:=0;
//建立一个钩子
Hhook:=SetWindowsHookEx(WH_Mouse,MouseC,HInstance,0);
end;end.
解决方案 »
- unable to load xx.dll
- delphi如何定义动态数组??
- 管理设备API SetupDiGetClassDevs 等一系列函数在 Delphi中的那个单元里面呢?
- 如何在主窗口中调用另一个非MDI窗口?
- 如何在Ttreeview动态增加一个项目
- excel源码
- 不行啦,不行啦,哪有Install Shield 6.3的中文语言包下载啊?up有分
- 关于maskedit 的问题
- SDAC批量更新数据
- 一个基础的OOP问题,我连如何陈述都不知道:( -新手问题!-
- 如何为数据模块添加TTable组件
- 如何能在formshow的事件中让label.Canvas.TextOut能写出字来?
在SysInit中声明,表示应用程序的句柄
Hhook:=SetWindowsHookEx(WH_JOURNALRECORD,MouseC,HInstance,0);