DELPHI QQ2008聊天内容获取

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Memo1: TMemo;
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Sign: string;
implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Title: array[0..255] of Char;
  QQText: Pchar;
  Long: Integer;
  hLastWin: THandle;
begin
  try
    Timer1.Enabled := False;
    hLastWin := GetForegroundWindow;
    Getwindowtext(hLastWin, Title, 255); //获取窗口标题
    if (Pos('交谈中', Title) > 0) then
    begin
      hLastWin := FindWindowEx(hLastWin, THandle(nil), '#32770', nil);
      if hLastWin = 0 then Exit;
      hLastWin := FindWindowEx(hLastWin, THandle(nil), 'RichEdit20A', nil);
      if hLastWin = 0 then Exit;
      Long := SendMessage(hLastWin, WM_GETTEXT, 0, 0) + 1;
      GetMem(QQText, Long);
      SendMessage(hLastWin, WM_GETTEXT, Long, Integer(QQText));
    end else Exit;
    try
      if QQText <> '' then
      begin
        Memo1.Text := QQText;
      end;
    finally
      FreeMem(QQText);
    end;
  finally
    Timer1.Enabled := True;
  end;
end;

end.

http://blog.sina.com.cn/s/blog_426a901f0100e5zr.html

原文地址:https://www.cnblogs.com/sunsoft/p/1964889.html