|
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
edtClassName: TEdit;
edtHwnd: TEdit;
Timer1: TTimer;
btnCancel: TButton;
edtTitle: TEdit;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure GetMousePosHwndAndClassName(Sender : TPoint); //自定义过程的声明
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hHWND: THandle;
function HookOn(lpHwnd:HWND;lpType ongint) ongint;stdcall;external 'Hook32.dll' name 'HookOn';
function HookOff:Boolean;stdcall;external 'Hook32.dll' name 'HookOff';
implementation
{$R *.dfm}
procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint); //自定义过程的实现部分
var
aName: array [0..255] of char;
tName: array [0..255] of char ;
begin
hHWND := WindowFromPoint(Sender); // windowfrompoint 获得窗口指定点的句柄
edtHwnd.Text := IntToStr(hHWND);
if boolean(GetClassName(hHWND,aName,256)) then
edtClassName.Text := string(aName)
else
edtClassName.Text := ' not found ! ';
if boolean(GetWindowText(hHwnd,tName,256)) then
edtTitle.Text := string(tName)
else
edtTitle.Text := ' not found ! ';
flashwindow(hHWND,true);
end; //这个过程大家都能看懂吧
procedure TForm1.FormCreate(Sender: TObject);
begin
image1.Picture.LoadFromFile('8.ico'); //IMAGE1 装载8.ico
Form1.FormStyle := fsStayOnTop; //窗体在最定层
Timer1.Interval := 50;
Timer1.Enabled:=false;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Timer1.Enabled:=true;
SetSystemCursor(LoadCursorFromFile('10.cur'),ocr_normal); //设置鼠标形状
image1.Picture.LoadFromFile('9.ico'); //装载图标
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SystemParametersinfo(SPI_SETCURSORS,0,nil,SPIF_SENDCHANGE); //设置系统的鼠标形状为默认
Timer1.Enabled:=false;
image1.Picture.LoadFromFile('8.ico');
HookOn(HWND(hHWND),wh_keyboard);
btnCancel.Enabled :=true;
image1.Enabled :=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
rPos: TPoint;
begin
if boolean(GetCursorPos(rPos)) then //getcursorPos 该函数检取光标的位置,以屏幕坐标表示。
GetMousePosHwndAndClassName(rPos); //调用自定义过程!
end;
procedure TForm1.btnCancelClick(Sender: TObject);
begin
HookOff();
btnCancel.Enabled :=false;
image1.Enabled :=true;
end;
end.
http://yunpan.cn/QXEZVjMHg9uU4 |
|