?? unit1.~pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Old:HWND;
implementation
{$R *.dfm}
//獲得窗口文本
function GetWndText(hWnd: HWND): String;
Var
Ret:LongInt;
mText:PChar;
Buf:Integer;
begin
Ret:=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0)+1;
GetMem(mText,Ret);
try
Buf:=LongInt(mText);
SendMessage(hWnd,WM_GETTEXT,Ret,Buf);
Result:=StrPas(mText);
finally
FreeMem(mText,Ret);
end;
end;
// 發送文本到窗口
procedure SetWndText(hWnd: HWND; Text: String);
Var
//Ret:LongInt;
mText:PChar;
Buf:Integer;
begin
GetMem(mText,Length(Text));
StrCopy(mText,PChar(Text));
try
Buf:=LongInt(mText);
SendMessage(hWnd,WM_SETTEXT,0,Buf);
finally
FreeMem(mText,Length(Text));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hQQ ,hChild,hRichText: hwnd;
RichEditTest:array [0..2048] of Char;
begin
//查找QQ
hQQ := FindWindowEx(0, //Parent
0, //Child
'#32770', //窗口類名通過Spy++或者MiniSpy都可以查到
nil //窗口Caption
);
//循環查找
While (hQQ <> 0) do //and (hSend = 0)
begin
if Old=hQQ then exit else
begin
if (Pos('聊天中',GetWndText(hQQ))>0) or
(Pos('發送消息',GetWndText(hQQ))>0) or
(Pos('群',GetWndText(hQQ))>0) then
begin
//hChild:=GetDlgItem(hQQ,0);
//hRichText := GetDlgItem(GetDlgItem(hChild,0), 894);
//hChild:=GetDlgItem(hQQ,$0000000);
// hRichText:=getwindow(hChild,GW_CHILD);
// Memo1.Text:=GetWndText(hRichText);
// setWndText(hRichText,'haha');
hChild:=GetDlgItem(hQQ,0);//Control ID使用Spy++很容易就可以找到,這是第一個子窗口的句柄
hRichText:=GetDlgItem(hChild,$380);//這個是消息框的句柄,380就是用Spy++找到的
//SendMessage(hRichText,WM_GETTEXT,2048,Integer(@RichEditTest));//發送WM_GETTEXT消息
//Form1.Memo1.Lines.Add(RichEditTest);
Memo1.Lines.Add(GetWndText(hRichText));
Form1.Memo1.Lines.Add('=================');
Old:=hQQ;
exit;
end;
end;
//查找QQ
hQQ := FindWindowEx(0, //Parent
hQQ, //Child
'#32770', //窗口類名通過Spy++或者MiniSpy都可以查到
nil //窗口Caption
);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
sendMytext(Memo1.Handle);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -