FindWindow通过关键字查找窗口标题的示例delphi源码
FindWindow通过关键字查找窗口标题的示例delphi源码// 可放在某单元中,uses Windows, Forms, SysUtils。
function FindByKeyword(const Keyword: string): HWND;
var
h: HWND;
len: Integer;
title: string;
begin
Result := 0;
h := GetWindow(GetDesktopWindow, GW_CHILD);
while h <> 0 do
begin
len := GetWindowTextLength(h);
if len > 0 then
begin
SetLength(title, len);
GetWindowText(h, PChar(title), len + 1);
if Pos(Keyword, title) > 0 then
begin
ShowMessage(title);// AfxMessageBox 等效
Result := h;
Exit;
end;
end;
h := GetWindow(h, GW_HWNDNEXT);
end;
end;
页:
[1]