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


本文整理自网络,侵删。

 
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.


//效果图:

相关阅读 >>

Delphi 更改窗体为顶层窗体不闪烁

Delphi+汇编例子

Delphi windows服务控制单元

Delphi 判断一个颜色是否是亮色

Delphi settextbuf

Delphi savelog 方便的记录日志

Delphi 窗体form的formstyle属性设置为fsstayontop时属性设置不起作用问题探讨。

Delphi 如何将bitmap位图与base64字符串相互转换

Delphi xe5开发的android手机截屏功能

Delphi 使窗口透明,并透过透明的窗口操作下面的窗口

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...