English 中文(简体)
Mo-冻结方案
原标题:Mouse hook - freezing program
  • 时间:2012-01-13 15:30:50
  •  标签:
  • delphi
  • hook

我下载了一个烟.样本,该样本没有工作。 因此,我 stripped掉了所有不必要的 st子,并想知道其中什么是错的。 当我开始该方案时,该方案和德尔菲冻结方案,我不得不通过任务结束。

申请:

type
...
    procedure ms(var message: tmessage); message WM_USER+1234;

  end;

var
  MainHookTestForm: TMainHookTestForm;

implementation
procedure HookMouse; stdcall; external  MouseHook.DLL ; // Added stdcalls;
procedure UnHookMouse; stdcall; external  MouseHook.DLL ;

{$R *.dfm}    

procedure TMainHookTestForm.FormCreate(Sender: TObject);
begin
  HookMouse;
end;

procedure TMainHookTestForm.FormDestroy(Sender: TObject);
begin
  UnHookMouse;
end;

procedure TMainHookTestForm.ms(var message: tmessage);
begin
  Label1.Caption:=format( %d - %d ,[message.LParam, message.WParam]); // Edited
end;

Lib:

library MouseHook;
uses
  Forms,
  Windows,
  Messages;

var Hook: HHOOK;
{$R *.res}

function HookProc(nCode: Integer; MsgID: WParam; Data: LParam): LResult; stdcall;
var
  mousePoint: TPoint;
begin
  mousePoint := PMouseHookStruct(Data)^.pt;
  PostMessage(FindWindow( TMainHookTestForm ,  Main ), WM_USER+1234, mousePoint.X, mousePoint.Y); // Edited class name
  Result := CallNextHookEx(Hook,nCode,MsgID,Data);
end;

procedure HookMouse; stdcall;
begin
  if Hook = 0 then Hook:=SetWindowsHookEx(WH_MOUSE,@HookProc,HInstance,0);
end;

procedure UnHookMouse; stdcall;
begin
  UnhookWindowsHookEx(Hook);
  Hook:=0;
end;

exports
  HookMouse, UnHookMouse;

begin
end.

我认为,这是很简单的。 冻结是在<代码>HookMouse的号召下进行的,执行这一条线时,整个民主选举学会冻结,我可以进一步推敲。 但我看不到这一程序有任何错误。

I am using XE2, if that helps. Thanks for the troubleshooting


<><>><>>>>>>>>: I edited the calls of HookMouse and UnhookMouse with stdbet; and the name of thewn to found. 现在似乎在工作 n,它显示了正确的价值,只有在 mo曲者不处在 app窗下的情况下,才会显示最佳的数值——当我把 mo改到窗户时,它会修改,停止更新。 是什么原因?

最佳回答

你的法典有几个问题。

1. 导言 页: 1 公约:

procedure HookMouse; stdcall; external  MouseHook.DLL ;
procedure UnHookMouse; stdcall; external  MouseHook.DLL ;

2. 结 论 你们正在以主要形式改变上限。 www.un.org/spanish/ecosoc (DLL)只有一次找到窗户。 你们可以利用猛虎人解组织进行欺骗:

procedure TMainHookTestForm.ms(var message: tmessage);
begin
  Memo1.Lines.Add(format( %d - %d ,[message.LParam, message.WParam]));
end;

2.1. 类别名称MainHook TestForm不正确。 应:

FindWindow( TMainHookTestForm ,  Main )

注:<>t MainHookForm

3. 在<代码>HookProc上,你必须使用:

if nCode = HC_ACTION then
begin
  mousePoint := PMouseHookStruct(Data)^.pt;      
  PostMessage(FindWindow( TMainHookTestForm ,  Main ), WM_USER+1234, mousePoint.X, mousePoint.Y);
end;  

Result := CallNextHookEx(Hook,nCode,MsgID,Data);
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签