WinAPI: WindowFromPoint- 獲取指定點所在窗口的句柄
//聲明: 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. //效果圖: