gpt4 book ai didi

delphi - getwindowtext 不检索文本

转载 作者:行者123 更新时间:2023-12-03 18:01:33 26 4
gpt4 key购买 nike

我尝试了以下代码,但它没有从前景窗口检索文本!

procedure TForm1.Button1Click(Sender: TObject);
var
title : pansichar;
s : string;
begin
GetWindowText(GetForegroundWindow(), title,GetWindowTextLength(GetForegroundWindow()) + 1);
s := title;
showmessage(s);
end;

最佳答案

使用这个:

var
hwndForeground: HWND;
titleLength: Integer;
title: string;
begin
hwndForeground := GetForegroundWindow();
titleLength := GetWindowTextLength(hwndForeground);
SetLength(title, titleLength);
GetWindowText(hwndForeground, PChar(title), titleLength + 1);
title := PChar(title);

ShowMessage(title);
end;

关于delphi - getwindowtext 不检索文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1433877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com