2

次のコードを試しましたが、フォアグラウンドウィンドウからテキストが取得されません!

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

5 に答える 5

11

これを使用してください:

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;
于 2009-09-16T17:08:38.440 に答える
3

この行を置き換えます:

  title : pansichar;

これとともに:

  title: array[0..255] of Char;
于 2009-09-16T16:16:19.387 に答える
2

このコードを試してください

procedure TForm1.Button1Click(Sender: TObject);
 var
  title : array[0..254] of Char;
  s : string;
begin
    GetWindowText(GetForegroundWindow(), title,255);
    s := title;
    showmessage(s);
end;

さよなら。

于 2009-09-16T16:16:28.010 に答える
1
プロシージャTForm1.Button1Click(送信者:TObject);
var
  liHwnd、liLength:整数;
  lpChar:PChar;
始める
  liHwnd:= GetForegroundWindow();
  liLength:= GetWindowTextLength(liHwnd)+ 1;
  lpChar:= StrAlloc(liLength);
  試す
    GetWindowText(liHwnd、lpChar、liLength);

    showmessage(lpChar);
  ついに
    StrDispose(lpChar);
  終わり;
終わり;
于 2009-09-28T14:37:14.283 に答える
0

あなたがこの問題を抱えているということでしょうか?

于 2009-09-17T06:38:31.063 に答える