博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
delphi对窗体的查询(delphi xe2)
阅读量:4633 次
发布时间:2019-06-09

本文共 2587 字,大约阅读时间需要 8 分钟。

1、显示所有窗口的标题

2、根据关键字查询窗口

3、某一窗口内的所有控件及其内容

.

unit Unit1;interfaceuses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,  System.Classes, Vcl.Graphics,  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    Button2: TButton;    Button3: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);  private    { Private declarations }    procedure get_actrlh(h: hwnd);  public    { Public declarations }  end;var  Form1: TForm1;  hi: integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var  szText: array [0 .. 254] of char;  hCurrentWindow: hwnd;begin  memo1.Clear;  hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);  while hCurrentWindow <> 0 do  begin    if GetWindowText(hCurrentWindow, @szText, 255) > 0 then      Memo1.lines.Add(szText);    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);  end;end;procedure TForm1.Button2Click(Sender: TObject);var  szText: array [0 .. 254] of char;  hCurrentWindow: hwnd;begin  memo1.Clear;  hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);  while hCurrentWindow <> 0 do  begin    if GetWindowText(hCurrentWindow, @szText, 255) > 0 then      if pos('360', szText) <> 0 then // 这里指定某一窗口,可能有多个        Memo1.lines.Add(szText);    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);  end;end;procedure TForm1.Button3Click(Sender: TObject);var  szText: array [0 .. 254] of char;  hCurrentWindow: hwnd;begin  memo1.Clear;  hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);  while hCurrentWindow <> 0 do  begin    if GetWindowText(hCurrentWindow, @szText, 255) > 0 then      if pos('360安全浏览器', szText) <> 0 then // 这里指定某一窗口,可能有多个      begin        Memo1.lines.Add(szText);        hi := 0;        get_actrlh(hCurrentWindow); // 获取窗口中的所有控件      end;    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);  end;end;function gettext(h: hwnd): string;var  name: string;  txtlen: integer;begin  txtlen := sendmessage(h, wm_gettextlength, 0, 0) + 1;  setlength(name, txtlen);  sendmessage(h, wm_gettext, txtlen, LongInt(@name[1]));  result := name;end;procedure TForm1.get_actrlh(h: hwnd);var  s: Array [0 .. 255] of char;begin  h := GetWindow(h, GW_child);  while h > 0 do  begin    GetClassName(h, s, 256);    begin      Memo1.lines.Add(inttostr(hi) + ':' + s + ':' + trim(gettext(h)));    end;    hi := hi + 1;    get_actrlh(h);    h := GetWindow(h, GW_HWNDNEXT);  end;end;end.

 

 

转载于:https://www.cnblogs.com/cuibq/archive/2011/11/16/3801907.html

你可能感兴趣的文章
poj2135最小费用最大流经典模板题
查看>>
hdu 4355 Party All the Time (2012 Multi-University Training Contest 6 ) 三分搜索
查看>>
POJ 2528 Mayor's posters(线段树)
查看>>
【转】[退役]纪念我的ACM——headacher@XDU
查看>>
利用STl实现队列
查看>>
android中The connection to adb is down,问题和解决 AndroidEclipseAntXML
查看>>
项目需求分析与建议
查看>>
UVa 10112 - Myacm Triangles
查看>>
给同一个按钮添加单双击事件
查看>>
form
查看>>
powershell输出错误信息到文件
查看>>
VS不显示最近打开的项目
查看>>
wcf客户端捕获异常
查看>>
MyEclipse安装Freemarker插件
查看>>
计算多项式的值
查看>>
DP(动态规划)
查看>>
chkconfig
查看>>
day44前端开发1之html基础
查看>>
小甲鱼-004改进小游戏
查看>>
琐碎的思绪
查看>>