procedure TMainForm.btnFindMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bIsDown := False;
if hOldWindow <> 0 then
begin
InvalidateRect(hOldWindow, nil, True);
hOldWindow := 0;
end;
end;
procedure TMainForm.btnFindMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
szClassName: array[0..255] of Char;
szCaption: array[0..255] of Char;
hCurWindow, hWindowDC: THandle;
rc: TRect;
CurPt: TPoint;
begin
if bIsDown then
begin
GetCursorPos(CurPt);
hCurWindow := WindowFromPoint(CurPt);
if hCurWindow <> 0 then
begin
GetClassName(hCurWindow, szClassName, 255);
GetWindowText(hCurWindow, szCaption, 255);
if szCaption = '' then
szCaption := '无标题';
lblCaption.Caption := szCaption;
lblClass.Caption := szClassName;
if (hOldWindow <> 0) and (hCurWindow <> hOldWindow) then
InvalidateRect(hOldWindow, nil, True);
hWindowDC := GetDC(hCurWindow);
Windows.GetClientRect(hCurWindow, rc);
FrameRect(hWindowDC, rc, Canvas.Brush.Handle);
使用勾子:
procedure TForm1.Button1Click(Sender: TObject);
var lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
begin
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found := Process32First(Hand,lppe);
if found then
begin
found := Process32Next(Hand,lppe);
end;
end;
或作用下面的方法:
procedure GetOtherText;
var TextLen: Integer;
TextStr: PChar;
PassHandle1,PassHandle:Hwnd;
PointPos: TPoint;
begin
try
GetCursorPos(PointPos);
PassHandle:=WindowFromPoint(PointPos);
if PassHandle=NULL then exit;
TextLen:=GetWindowTextLength(PassHandle)+1; //得到名字长度,并将长度加1
if TextLen <= 1 then exit;
GetMem(TextStr, 255);
try
SendMessage(PassHandle, WM_GETTEXT, 255, Longint(TextStr));
Label1.Caption := (TextStr);
finally
FreeMem(TextStr);
end;
except
end;
end;
var
p:tpoint;
i:hwnd;
procedure tform1.timer1timer(var sender:tobject);
begin
begin
getcursorpos(p);
i:=windowfrompoint(p);
if i <> 0 then
edit1.text:='handle is'+inttostr(i);
end;