Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#12

Re: Kontextmenü einer anderen Anwendung aufrufen

  Alt 29. Okt 2006, 14:29
Hier mal ein Beispiel wie man Text aus einer anderen Anwendung ohne
Kontexmenü bekommen kann.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Label7: TLabel;
    Edit2: TEdit;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function LeftStr(Const Str: String; Size: Word): String;
begin
  Result := Copy(Str, 1, Size)
end;

function InStr(Start: integer; Source: string; SourceToFind: string): integer;
begin
  Result := pos(SourceToFind, copy(Source, Start, Length(Source) - (Start - 1)));
end;

procedure TForm1.Timer1Timer(Sender: TObject);
const
  MAX_BUFFER = 32767;

Var
 Res : Integer;
 Handle : HWND;
 Parent : HWND;
 Pt : TPOINT;
 Buffer : String;
 Klasse : String;

begin

    if GetCursorPos(Pt) then
    begin
      Handle := WindowFromPoint(Pt);
      Parent := GetParent(Handle);
                 SetLength(Klasse, 128);
      Res := GetClassName(Handle, PChar(Klasse), 128);
      Klasse := LeftStr(Klasse, Res);

      Label2.Caption := IntToStr(Handle);
      Label4.Caption := IntToStr(Parent);
      Label6.Caption := Klasse;

      If (InStr(1, Klasse, 'Edit') <> 0) Or (InStr(1, Klasse, 'text') <> 0) Then
        begin
          If RadioButton1.Checked = True Then
            begin
                          SetLength(Buffer, MAX_BUFFER);
            Res := SendMessage(Handle, WM_GETTEXT, Length(Buffer), Integer(PChar(Buffer)));
            Edit1.Text := LeftStr(Buffer, Res);
            end Else
            SendMessage(Handle, WM_SETTEXT, 0, Integer(Edit1.Text));
        end;
    end;
end;

end.
Gruß
  Mit Zitat antworten Zitat