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字符串加密解密

Delphi listview 设置固定列宽

Delphi 在桌面上画图

Delphi 跨平台的,在fmx中读取icon文件的每一帧到bitmap

Delphi 判断时间是否合法 -isvaliddatetime、isvaliddate、isvalidtime、isvaliddateday

Delphi.about.com一个钩子的实现代码

Delphi xe intraweb 程序在iis下的发布详细教程

delhpi如何直接获得webbrowser输入的xml文件

Delphi编辑环境

Delphi webbrowser获取页面全部链接

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



打赏

取消

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

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

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

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

评论

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