خرید بک لینک

سلامی دوباره خدمت دوستان

میخوام تمام رویدادهای موس رو هوک کنم و مشکل اینجاست که با کد زیر فقط پروسه خود برنامه هوک میشه (در صورت به کار بردن GetCurrentThreadId) وقتی هم بجای GetCurrentThreadIdصفر میگذارم که کل ویندوز زو هوک کنه در ویندوز 10 که هیچ اتفاقی نمی افته ولی در ویندوز xp کد کار میکنه اما پروسه Explorer پیغام خطا میده.

دوستان ممنون میشم راهنمایی کنید

unit Unit1;

interface

uses
Winapi.Windows, System.SysUtils,
System.Classes,
Vcl.Controls, Vcl.Forms, Vcl.StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Button3: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function myHookProc(code: Integer; wParam, lParam: LongInt)
: NativeUInt; stdcall;

var
Form1: TForm1;
myHook: hHook;

implementation

function myHookProc(code: Integer; wParam, lParam: LongInt): NativeUInt;
var
X, Y: Integer;

begin
X := PMouseHookStruct(lParam).pt.X;
Y := PMouseHookStruct(lParam).pt.Y;
Form1.Label1.Caption := IntToStr(X) + ' : ' + IntToStr(Y);

Form1.Caption := IntToStr(wParam);

result := CallNextHookEx(myHook, code, wParam, lParam);
end;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if (myHook <= 0) then
begin
// myHook := SetWindowsHookEx(WH_MOUSE, @myHookProc, HInstance,
// GetCurrentThreadId);

myHook := SetWindowsHookEx(WH_MOUSE, @myHookProc, HInstance,
0);
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UnhookWindowsHookEx(myHook);
myHook:= 0;
end;

end.

Image 2.jpg

- - , .

برچسب: نویسنده: محمد رضا جوادیان تاريخ: چهارشنبه 7 بهمن 1394 ساعت: 4:51

صفحه بندی