delphi fmx 获取控件句柄  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.03279185295105 seconds