全局钩子,如何实现全局鼠标右键按下,Cursor更改为自定义图标,弹起右键,恢复系统默认,帮忙检查下代码哪里不对。谢谢!(100)

  • 主题发起人 主题发起人 zw963
  • 开始时间 开始时间
Z

zw963

Unregistered / Unconfirmed
GUEST, unregistred user!
100分求助:如何实现全局(整个桌面区域)鼠标右键按下,Cursor更改为自定义图标(并实现一些功能),弹起右键,恢复系统默认图标。有两个问题:1、我的如下代码只能在窗体范围内实现类似,一旦离开窗体,点击鼠标右键,就不会更改系统Cursor,请问代码那里有问题?2、以下红色代码部分,如果去掉注释(增加显示一个对话框),更改Cursor后,却无法自动恢复,请问代码那里有问题?Dll的代码如下:
代码:
library HookDll;uses  SysUtils,Classes,Windows,Messages,Extctrls,Dialogs;{$R *.res}varhHook1: HHOOK;procedure ChangeCursorAndLockCursor;var  h: HCursor;begin  h:= LoadCursorFromFile('SCrolling.ico');  SetSystemCursor(h,OCR_NORMAL);//...end;procedure RestoreCursor;begin  SystemParametersinfo(SPI_SETCURSORS,0,nil,SPIF_SENDCHANGE);end;function hookProc(  nCode: Integer; //hook code  WParam: WPARAM; //message identifier  LParam: LPARAM//mouse coordinate):LRESULT;stdcall;begin  if wParam = WM_RBUTTONDOWN then  begin    ChangeCursorAndLockCursor;[red]    //ShowMessage('Hook start');[/red]  end;  if WParam = WM_RBUTTONUP then  begin    RestoreCursor;  end;  Result:= CallNextHookEx(hHook1,nCode,wParam,lParam);end;function setHook:Boolean;stdcall;begin  hHook1:= SetWindowsHookEx(WH_MOUSE,@hookProc,Hinstance,0);  Result:= hHook1<>0;end;function delHook:Boolean;stdcall;begin  Result:= UnhookWindowsHookEx(hHook1);end;exports  setHook name 'setHook',  delHook name 'delHook',  hookProc name 'hookProc';end.
主程序代码:
代码:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Label1: TLabel;  private    { Private declarations }  public    Constructor Create(AOwner: TComponent);override;    Destructor Destroy;override;    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.dfm}function setHook:Boolean;external 'Hookdll.dll' name 'setHook'function delHook:Boolean;external 'Hookdll.dll' name 'delHook'Constructor Tform1.Create(AOwner: TComponent);  begin    inherited;    sethook;    form1.Label1.Caption:='Hook Start';  end;  Destructor Tform1.Destroy;  begin    delHook;    inherited;  end;end.
 
做外挂的,去广海看看
 
在里面先releacecapure,试下
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部