测试:

函数代码:

function FindWindowXG(strClass, strTitle: string): THandle;
var
hd: THandle;
arrClass: array[..] of Char;
arrTitle: array[..] of Char;
wClass, wTitle: string;
begin
hd := GetWindow(Application.Handle, GW_HWNDFIRST);
while hd > do
begin
GetClassName(hd, @arrClass[], Length(arrClass));
GetWindowText(hd, @arrTitle[], Length(arrTitle)); wClass := arrClass;
wTitle := arrTitle; strClass := Trim(strClass);
strTitle := Trim(strTitle);
if (Length(strClass) > ) and (Length(strTitle) = ) then
begin
if UpperCase(strClass) = UpperCase(wClass) then
begin
Result := hd;
Exit;
end;
end; if (Length(strClass) = ) and (Length(strTitle) > ) then
begin
if Pos(UpperCase(strTitle), UpperCase(wTitle)) > then
begin
Result := hd;
Exit;
end;
end; if (Length(strClass) > ) and (Length(strTitle) > ) then
begin
if (UpperCase(strClass) = UpperCase(wClass))
and (Pos(UpperCase(strTitle), UpperCase(wTitle)) > ) then
begin
Result := hd;
Exit;
end;
end; hd := GetNextWindow(hd, GW_HWNDNEXT);
end; Result := ;
end;

测试代码:

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls; type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} function FindWindowXG(strClass, strTitle: string): THandle;
var
hd: THandle;
arrClass: array[..] of Char;
arrTitle: array[..] of Char;
wClass, wTitle: string;
begin
hd := GetWindow(Application.Handle, GW_HWNDFIRST);
while hd > do
begin
GetClassName(hd, @arrClass[], Length(arrClass));
GetWindowText(hd, @arrTitle[], Length(arrTitle)); wClass := arrClass;
wTitle := arrTitle; strClass := Trim(strClass);
strTitle := Trim(strTitle);
if (Length(strClass) > ) and (Length(strTitle) = ) then
begin
if UpperCase(strClass) = UpperCase(wClass) then
begin
Result := hd;
Exit;
end;
end; if (Length(strClass) = ) and (Length(strTitle) > ) then
begin
if Pos(UpperCase(strTitle), UpperCase(wTitle)) > then
begin
Result := hd;
Exit;
end;
end; if (Length(strClass) > ) and (Length(strTitle) > ) then
begin
if (UpperCase(strClass) = UpperCase(wClass))
and (Pos(UpperCase(strTitle), UpperCase(wTitle)) > ) then
begin
Result := hd;
Exit;
end;
end; hd := GetNextWindow(hd, GW_HWNDNEXT);
end; Result := ;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text := IntToStr(FindWindowXG(Edit1.Text,Edit2.Text));
end; procedure TForm1.Edit1Change(Sender: TObject);
begin
Edit3.Clear
end; procedure TForm1.Edit2Change(Sender: TObject);
begin
Edit3.Clear
end; end.

FindWindowXG的更多相关文章

随机推荐

  1. 「学习笔记」Treap

    「学习笔记」Treap 前言 什么是 Treap ? 二叉搜索树 (Binary Search Tree/Binary Sort Tree/BST) 基础定义 查找元素 插入元素 删除元素 查找后继 ...

  2. Python输出三位数以内的水仙花数

    num = 100 while num <= 999: a = num % 10 #取个位数 b = num // 10 % 10 #取十位数 c = num // 100 #取百位数 if n ...

  3. css实现单行居中,两行居左

    居中需要用到 text-align:center,居左是默认值也就是text-align:left.要让两者结合起来需要多一个标签. <h2><p>单行居中,多行居左</ ...

  4. Day1学习总结

    # 1.print()# 2.input()# 3.if:# elif# else#4.while循环#5.for i in range()#6.break.continue#7.import ran ...

  5. Hystrix熔断机制导致误报请求超时错误

    问题的过程如下: (1)前端向服务端请求往HBase插入1000条数据: (2)请求经路由网关Zuul传递给HBaseService,HBaseService执行插入操作: (3)插入操作需要的时间超 ...

  6. 微信web版接口api(转)

    安卓微信的api,个人微信开发API协议,微信 ipad sdk,微信ipad协议,微信web版接口api,微信网页版接口,微信电脑版sdk,微信开发sdk,微信开发API,微信协议,微信接口文档sd ...

  7. redis api-set

  8. [易语言][ExDui][Tutorial]1.NameSelector

    咕咕咕 尝试自己写组件对象被易语言的对象劝退后,我又回来写教程了. 相信上一章对如何创建窗口讲得足够透彻了,这一章上项目实战:点名器. 点名器这种简单的东西实在是经常被拿出来开刀啊. 还有一点,发现之 ...

  9. 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:包装类

    public class WrapperDemo01{ public static void main(String args[]){ int x = 30 ; // 基本数据类型 Integer i ...

  10. 白手起家Django项目发布上篇_linux centos 环境部署

    在项目发布之前,首先准备好我们编写好的Django项目,这个我们在之后博客有写,大家可以去看, 首先,先开始安装linux服务器,作为Django项目的发布服务器.以Vmware虚拟机为例子,大家也可 ...