Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#14

Re: Text in Eingabefeld beliebiger Anwendungen ersetzen?

  Alt 11. Feb 2005, 10:07
@toms: SDC??

Ich hab jetzt mal meinen Code etwas erweitert... jetzt blinken die betreffenden Controls (ausser beim IE, dort blinkt das gesamte Fenster und nicht nur das aktive Control) ... mehr bekomme ich im Moment damit allerdings nicht gebacken
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
var
  AppHWnd: HWND;
  ThreadId: DWORD;
  FocusHWnd: HWND;
  ClassName: string;
  S0, S1: string;
  Rect: TRect;
  Canvas: TCanvas;
  Loop: integer;
begin
  Timer1.Enabled := False;
  FocusHWnd := GetFocus;
  if not IsWindow(FocusHWnd) then
  begin
    AppHWnd := GetForegroundWindow;
    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);

          SetLength(ClassName, 512);
          SetLength(ClassName, GetClassName(FocusHWnd, PChar(ClassName),
            Length(ClassName)));

          SetLength(S0, SendMessage(FocusHWnd, WM_GETTEXTLENGTH, 0, 0) + 1);
          if Length(S0) > 1 then
          begin
            Application.ProcessMessages;
            SetLength(S0, SendMessage(FocusHWnd, WM_GETTEXT, Length(S0),
              LPARAM(PChar(S0))));
            S1 := StringReplace(S0, '###Hierhin###', 'Neuer Text',
              [rfReplaceAll]);
            if S0 <> S1 then
              SendMessage(FocusHWnd, WM_SETTEXT, Length(S1), LPARAM(PChar(S1)));
          end
          else
          begin
            //Get editor co-ordinates
            Windows.GetClientRect(FocusHWnd, Rect);
            //Change width/height to be right/bottom
            Rect.BottomRight := Point(Rect.Left + Rect.Right, Rect.Top +
              Rect.Bottom);
            //Turn client-relative co-ordinates into screen-relative co-ordinates
            Windows.ClientToScreen(FocusHWnd, Rect.TopLeft);
            Windows.ClientToScreen(FocusHWnd, Rect.BottomRight);
            //Set up canvas for whole desktop and flash the editor a few times
            Canvas := TCanvas.Create;
            try
              Canvas.Pen.Mode := pmNot;
              Canvas.Pen.Width := 5;
              Canvas.Handle := GetDC(HWnd_Desktop);
              try
                for Loop := 1 to 8 do
                begin
                  Canvas.Polyline([Rect.TopLeft, Point(Rect.Right, Rect.Top),
                    Rect.BottomRight, Point(Rect.Left, Rect.Bottom),
                      Rect.TopLeft]);
                  Sleep(100);
                end
              finally
                ReleaseDC(HWnd_Desktop, Canvas.Handle)
              end;
            finally
              Canvas.Free
            end;
          end;
        end;
    end;
  end;

  if (ListView1.Items.Count = 0) or (ListView1.Items[ListView1.Items.Count -
    1].Caption <> IntToStr(FocusHWnd) + '[' + ClassName + ']="' + Trim(S0) + '"')
      then
  begin
    ListView1.Items.BeginUpdate;
    ListView1.Items.Add;
    ListView1.Items[ListView1.Items.Count - 1].Caption := IntToStr(FocusHWnd) +
      '[' + ClassName + ']="' + Trim(S0) + '"';
    ListView1.Items[ListView1.Items.Count - 1].MakeVisible(False);
    ListView1.Items.EndUpdate;
  end;
  Timer1.Enabled := True;
end;
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat