Delphi fmx 获取控件句柄


本文整理自网络,侵删。

 Delphi fmx 获取控件句柄
Fmx 框架控件如果 从 TPresentedControl 类继承下来的,会有一个属性,ControlType,它是一个枚举。

打开 FMX.Controls 单元定义:TControlType = (Styled, Platform);   

控件的ControlType属性默认为 Styled,如果使用 Platform ,则使用当前平台原生创建。

在 Win 平台原生创建是有句柄的。我通过遍历里面的对象,获取到它的 TWinNativeScene 类,取出句柄。

原码如下:

uses

  FMX.Controls.Presentation, FMX.Presentation.Win.Style, FMX.Controls 


function FmxObjectToWnd(FmxControl: TPresentedControl):NativeUInt;
var
  Idx: Integer;
begin
  Result:= 0;
  if FmxControl.ControlType = TControlType.Platform then
  for Idx := 0 to FmxControl.ChildrenCount - 1 do begin
    if FmxControl.Children[Idx] is TWinNativeScene then begin
      Exit(TWinNativeScene(FmxControl.Children[Idx]).Handle.Wnd);
    end;
  end;
end;

 

调用方法:

  把控件属性 ControlType 设置为 Platform ,直接调用

      Showmessage(  IntToStr( FmxObjectToWnd(Panel1) )  ) ;

 

来源:http://delphifmx.com/node/80

相关阅读 >>

Delphi tms web core 实现下载

Delphi 进程保护

Delphi中format函数的用法

Delphi xe5 android得到手机的手机号码

Delphi tclientdataset的使用

Delphi 实现定时功能

Delphi 正则判断是否包含数字

Delphi 限制edit输入 多个例子

Delphi 获取动态创建的image与scrollbox的相对位置

Delphi字符串加密解密

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



打赏

取消

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

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

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

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

评论

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