1.获取当前所有窗口

procedure TForm1.Button1Click(Sender: TObject);
var
 szText: array[0..254] of char;
 hCurrentWindow :hwnd;
begin
hCurrentWindow := GetWindow(Handle,GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
    if GetWindowText(hCurrentWindow ,@szText,255) > 0 then
    memo1.lines.Add(StrPas(@szText));
    hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);
 end;
end;
 
2.获取某一指定窗口

procedure TForm1.Button1Click(Sender: TObject);
var
 szText: array[0..254] of char;
 hCurrentWindow :hwnd;
begin
hCurrentWindow := GetWindow(Handle,GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
    if GetWindowText(hCurrentWindow ,@szText,255) > 0 then

if  pos('RTX 会话',  StrPas(@szText))<>0 then  //这里指定某一窗口,可能有多个
    memo1.lines.Add(StrPas(@szText));
    hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);
 end;
end;

3.获取某一窗口内的所有控件及其内容
  unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure get_actrlh(h:hwnd);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 hi:integer;

implementation

{$R *.dfm}

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;

procedure TForm1.Button1Click(Sender: TObject);
var
 szText: array[0..254] of char;
 hCurrentWindow :hwnd;
begin
   hCurrentWindow := GetWindow(Handle,GW_HWNDFIRST);
   while hCurrentWindow <> 0 do
   begin
    if GetWindowText(hCurrentWindow ,@szText,255) > 0 then

if  pos('RTX 会话',  StrPas(@szText))<>0 then  //这里指定某一窗口,可能有多个
    begin
    memo1.lines.Add(StrPas(@szText));
    hi:=0;
    get_actrlh(hCurrentWindow);//获取窗口中的所有控件

end;

hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);
 end;
end;
end.

4.获取窗口中的某个控件,并对其操作

首先用上面3中的程序,根据窗口中控件的特性,找到你要操作的控件的序号,
即memo1中左边的数字,用变量hnum保存这一序号,再把上面3中的程序稍作修改如下,

以下其实是一个完整的、功能简单的、没有经过优化的腾讯通RTX自动回复消息程序:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure get_actrlh(h:hwnd);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 hi,hnum:integer;

implementation

{$R *.dfm}

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)) );

if hi=hnum then
      begin
      memo1.lines.Add('上面为找到的控件');
      SendMessage(h,WM_SETTEXT,0,Integer(pchar('*此为RichEdit20W所赋的文本')));

end;
    end ;

hi:=hi+1;
       get_actrlh(h);
       h:=GetWindow(h,GW_HWNDNEXT);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 szText: array[0..254] of char;
 hCurrentWindow :hwnd;
begin
   hCurrentWindow := GetWindow(Handle,GW_HWNDFIRST);
   memo1.Clear;
   while hCurrentWindow <> 0 do
   begin
    if GetWindowText(hCurrentWindow ,@szText,255) > 0 then

if  pos('RTX 会话',  StrPas(@szText))<>0 then  //这里指定某一窗口,可能有多个
    begin
    memo1.lines.Add(StrPas(@szText));
    hi:=0;
    hnum:=3; //此为所要赋值的RichEdit20W控件在窗口中的序号
    get_actrlh(hCurrentWindow);//获取窗口中的所有控件

//以下向窗口发送ALT_S 组合键,实现腾讯通RTX发送消息

SetForegroundWindow(hCurrentWindow);//设置窗口为当前窗口
  keybd_event(VK_menu,MapVirtualKey(VK_menu,0),0,0);
  sleep(1000);
  keybd_event(83,MapVirtualKey(83,0),0,0);
  sleep(1000);
  keybd_event(83,MapVirtualKey(83,0),KEYEVENTF_KEYUP,0);
  keybd_event(VK_menu,MapVirtualKey(VK_menu,0),KEYEVENTF_KEYUP,0);

end;

hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);
 end;
end;
end.

delphi有关获取其他程序的窗口及对窗口内控件的操作的更多相关文章

  1. WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里?

    原文:WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里? 在 WPF 程序中,我们有 Mouse.GetPosition(IInputElement relativeTo) 方法可以拿到鼠标 ...

  2. delphi 一个自动控制机的硅控板检测程序,用多线程和API,没有用控件,少做改动就能用 用485开发

    一个自动控制机的硅控板检测程序,用多线程和API,没有用控件,少做改动就能用Unit CommThread; Interface Uses  Windows, Classes, SysUtils, G ...

  3. SNF快速开发平台MVC-各种级联绑定方式,演示样例程序(包含表单和表格控件)

    做了这么多项目,经常会使用到级联.联动的情况. 如:省.市.县.区.一级分类.二级分类.三级分类.仓库.货位. 方式:有表单需要做级联的,还是表格行上需要做级联操作的. 实现:实现方法也有很多种方式. ...

  4. WPF 从程序集中检索图片资源stream给Image控件使用

    原文:WPF 从程序集中检索图片资源stream给Image控件使用 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/nihang1234/artic ...

  5. JS 获取某个容器控件中id包含制定字符串的控件id列表

    //获取某容器控件中id包含某字符串的控件id列表 //参数:容器控件.要查找的控件的id关键字 function GetIdListBySubKey(container,subIdKey) { va ...

  6. DELPHI XE10,JSON 生成和解析,再利用INDYHTTP控件POST

    Delphi XE10,Json 生成和解析,再利用indyhttp控件Post 年09月20日 :: 阅读数: --不多说,直接上代码 procedure TFrmMain.Brand; var J ...

  7. VC++如何在程序中用代码注册和卸载ocx控件(代码)

    方法一:在dos或Windows命令行下运行:regsvr32 ocxname.ocx 注册 示例:regsvr32 netshare.ocx     //注册netshare.ocx控件regsvr ...

  8. 在DevExpress程序中使用条形码二维码控件,以及进行报表打印处理

    在很多业务系统里面,越来越多涉及到条形码.二维码的应用了,不管在Web界面还是WInform界面都需要处理很多物料相关的操作,甚至很多企业为了减少录入错误操作,为每个设备进行条形码.二维码的标签,直接 ...

  9. 首发 手把手教你制作 Windows8 应用程序内部的 hubtile (动态瓷砖控件) MetroStyle(转)

    http://blog.csdn.net/wangrenzhu2011/article/details/8175492 (转) 在metro 风格中 动态磁贴是他的精髓 在wp7 的开发中 我们可以使 ...

随机推荐

  1. VsCode插件开发之入门示例

    主要参考官网:https://code.visualstudio.com/api/get-started/your-first-extension 其实也就三步 一.安装环境 npm install ...

  2. 超简单Mac安装Tomcat服务器

    超简单Mac安装Tomcat服务器 1.首先下载tomcat 下载连接 2. 解压并改名 3.把Tomcat复制到系统中的资源库或者Library 4.打开shell,进入Tomcat下面的bin目录 ...

  3. nginx-1.13.12 源码配置清单

    configure命令支持以下参数: --help打印帮助信息. --prefix=安装路径定义一个将保留服务器文件的目录.这个相同的目录也将被用于由configure(由库源创建的路径除外)和ngi ...

  4. Html5 标签二(超链接)

    1.五种超链接形式 2.超链接属性 一 五种超链接 <!DOCTYPE html> <html lang="en"> <head> <me ...

  5. [08] AOP基本概念和使用

    1.什么是AOP AOP = Aspect Oriental Programing,即面向切面编程.什么概念,我们看如下的图片: 三个方法中,重复使用了代码A和代码B,典型的场景比如"开启事 ...

  6. 大话设计模式:代理模式 C#

    学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现在,学习代表你的将来 所谓代理模式就是你去委托一个人帮你干一件事!例如:你委托我帮你谈恋爱,你委托我帮你陪你媳妇儿逛 ...

  7. 【强化学习】python 实现 q-learning 例一

    本文作者:hhh5460 本文地址:https://www.cnblogs.com/hhh5460/p/10134018.html 问题情境 -o---T# T 就是宝藏的位置, o 是探索者的位置 ...

  8. Bash Shebang 小结

    在 shell(Bash 是一种 shell) 中执行外部程序和脚本时,Linux 内核会启动一个新的进程,以便在新的进程中执行指定的程序或脚本.内核知道该如何为编译型的程序做这件事,但是对于脚本程序 ...

  9. ubuntu16.04在GTX1070环境下安装 cuda9.1

    设备要求 系统:Ubuntu16.04 显卡:GTX 1070 驱动:nvidia系列,显卡驱动的版本必须大于等于cuda的sh文件名里面的版本号 驱动可从 此处 下载,我已经整理好了 检查安装驱动 ...

  10. CentOS6.9下升级默认的OpenSSH操作记录(升级到OpenSSH_7.6p1)

    近期对IDC机房服务器做了一次安全漏洞扫描,漏扫结果显示服务器的OpenSSH版本太低(CentOS6默认是OpenSSH_5.3p1),存在漏洞隐患,安全部门建议升级到OpenSSH_7.6p1.升 ...