您的位置:首页 > 其它

WinAPI: WindowFromPoint- 获取指定点所在窗口的句柄

2008-09-11 10:16 555 查看
WinAPI: WindowFromPoint- 获取指定点所在窗口的句柄
[code]//声明:
WindowFromPoint(Point: TPoint): HWND;

//举例:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
h: HWND;
procedure TForm1.Timer1Timer(Sender: TObject);
var
pt: TPoint;
arr: array[0..254] of Char;
begin
if GetCursorPos(pt) then             {如果能获取点}
begin
h := WindowFromPoint(pt);          {返回句柄}
GetClassName(h, arr, Length(arr)); {获取该句柄窗口的类名}
Text := arr;                       {显示在标题}
end;
end;
end.

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: