新建工程,窗体上放置一个Button,一个Edit.使用方法:先点击button,然后点击想要得到句柄的窗体.下面是代码
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
setcapture(handle); // 设置捕获鼠标输入
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var point : TPoint;
hwnd : THandle;
begin
point.x := x;
point.y := y;
point := ClientToScreen(point); // 客户区坐标转换到屏幕坐标
hwnd := WindowFromPoint(point); // 取鼠标点击的窗体句柄
ReleaseCapture; // 终止捕获鼠标输入
if hwnd=handle then edit1.text := '没有点击其他窗体!'
else
edit1.Text := inttostr(hwnd); // 将捕捉到的窗体句柄显示在edit1中
end;
end.
To ;sbh410
你给的分太少了