Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#6

Re: Aktives Fenster ermitteln

  Alt 16. Dez 2005, 11:21
Das mit dem ForegroundWindow war schon die richtige Richtung.

Delphi-Quellcode:
function GetFocusedControl: HWnd;
var
  tid: Cardinal;
  hw: HWND;
begin
  hw := GetForegroundWindow;
  tid := GetWindowThreadProcessID(hw, nil);
  if AttachThreadInput(GetCurrentThreadID, tid, true)
    then Result := GetFocus
    else Result := HWND(-1);
  AttachThreadInput(GetCurrentThreadID, tid, false);
end;

procedure SendText(s: string);
var
  h: HWND;
  i: integer;
begin
  h := GetFocusedControl;
  for i := 1 to Length(s) do
    PostMessage(h, WM_CHAR, Word(s[i]), 0);
end;
Grüße vom marabu
  Mit Zitat antworten Zitat