Einzelnen Beitrag anzeigen

Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#15

Re: Text in Eingabefeld beliebiger Anwendungen ersetzen?

  Alt 11. Feb 2005, 10:08
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  S_SEARCH = '###Hierhin###';
  S_REPLACE = 'Neuer Text';
var
  AppHWnd: HWND;
  ThreadId: DWORD;
  FocusHWnd: HWND;
  ClsName: String;
  WndText: String;
begin

  AppHWnd := GetForegroundWindow;
  if IsWindow(AppHWnd) then
  begin
    if AppHWnd <> Self.Handle then
    begin
      ThreadId := GetWindowThreadProcessId(AppHWnd, nil);
      if ThreadId <> 0 then
        if AttachThreadInput(GetCurrentThreadId, ThreadId, True) then
        begin
          FocusHWnd := GetFocus;
          AttachThreadInput(GetCurrentThreadId, ThreadId, False);
        end;
    end else
      FocusHWnd := GetFocus;
    if IsWindow(FocusHWnd) then
    begin
      SetLength(ClsName, 512);
      SetLength(ClsName, GetClassName(FocusHWnd, PChar(ClsName), Length(ClsName)));
      SetLength(WndText, SendMessage(FocusHWnd, WM_GETTEXTLENGTH, 0, 0) + 1);
      SetLength(WndText, SendMessage(FocusHWnd, WM_GETTEXT, Length(WndText), LPARAM(PChar(WndText))));
      if Pos(S_SEARCH, WndText) > 0 then
      begin
        WndText := StringReplace(WndText, S_SEARCH, S_REPLACE, [rfReplaceAll]);
        SendMessage(FocusHWnd, WM_SETTEXT, Length(WndText), LPARAM(PChar(WndText)));
      end;
      with ListView1.Items.Add do
      begin
        Caption := '[' + ClsName + '] = "' + WndText + '"';
        MakeVisible(False);
      end;
    end;
  end;

end;
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat