测试:

函数代码:

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. LibreOJ #2006. 「SCOI2015」小凸玩矩阵

    想了挺久没想出来,一看题解恍然大悟.一个数对应一行和一列,二分答案,凡是小于等于答案的就连边.如果满足能够取出 \(n - k + 1\) 个不比二分中点 \(mid\) 大的数,那么r = mid, ...

  2. Pytorch 分割模型构建和训练【直播】2019 年县域农业大脑AI挑战赛---(四)模型构建和网络训练

    对于分割网络,如果当成一个黑箱就是:输入一个3x1024x1024 输出4x1024x1024. 我没有使用二分类,直接使用了四分类. 分类网络使用了SegNet,没有加载预训练模型,参数也是默认初始 ...

  3. 在cnblog中试用Markdown

    参考: http://www.cnblogs.com/cmt/p/markdown.html https://www.cnblogs.com/cmt/p/markdown-latex.html htt ...

  4. threading 多线程

    # coding:utf- import time from threading import Thread def foo(x):#这里可以带参数def foo(x) print "foo ...

  5. lambda表达式和for_each,find_if

    1 lambda表达式可以允许我传递任意可调用对象,必须要有捕获列表和函数体,标准形式是[捕获列表] (参数列表)->return tpye{函数体} 谓词:一元谓词指的是只能接受一个传入参数, ...

  6. Day9 - H - 最少拦截系统 HDU - 1257

    某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于 ...

  7. Html5使用audio播放音乐

    html代码 <audio  id="myaudio" src="http://ws.stream.qqmusic.qq.com/C100003R74Cn0JR4O ...

  8. 判断ES数据是否更新成功

    参考:https://stackoverflow.com/questions/38928991/how-to-detect-if-a-document-update-in-elasticsearch- ...

  9. 第1节 IMPALA:1、impala的基本介绍

    impala的介绍: impala是cloudera公司开源提供的一款高效率的sql查询工具 impala可以兼容hive的绝大多数的语法,可以完全的替代表hive impala与hive的关系:紧耦 ...

  10. Concurrent包下用过哪些类?

    1.executor接口,使用executor接口的子接口ExecutorService用来创建线程池2.Lock接口下的ReentrantLock类,实现同步,比如三个线程循环打印ABCABCABC ...