QQ2006测试通过:
function GetQQ(hd:HWND):BOOL;stdcall;
var
TitleText:array [0..255] of Char;
RichEditTest:array [0..2048] of Char;
FirstDlgHd,Richedit20AHd:HWND;
begin
GetWindowText(hd,TitleText,255);//取hd对应的窗口的标题
if ((Pos('与 ',TitleText)<>0)) and ((Pos(' 聊天中',TitleText)<>0)) or
(Pos(' - 发送消息',TitleText)<>0) or
(Pos(' - 群',TitleText)<>0)
then//根据QQ聊天窗口的特性来找句柄,比较简单,当然速度也比较慢,还有更好的办法,比如用钩子
begin
FirstDlgHd:=GetDlgItem(hd,0);//Control ID使用Spy++很容易就可以找到这是第一个子窗口的句柄
Richedit20AHd:=GetDlgItem(FirstDlgHd,$380);//这个是消息框的句柄
SendMessage(Richedit20AHd,WM_GETTEXT,2048,Integer(@RichEditTest));//发送WM_GETTEXT消息
Form1.Memo1.Lines.Add(RichEditTest);
Form1.Memo1.Lines.Add('=================');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@GetQQ,0);//遍历顶层窗口
end;