以前有人已经解决过这种问题请查即可。
贴出部分代码,由于qq 升级啦,最新版的可能不能用
查找句柄部分
//这个函数取当前qq发送窗口上“送讯息”的按钮的句柄
//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;
function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
//找到发消息的目标窗口的目标控件
if StrPas(Buffer)='Button' then
begin
GetWindowText(hwnd,buffer1,100);
if buffer1 = '送讯息(&S)' then
begin
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;
end;//end of function
//这个函数取当前qq发送窗口上消息框句柄
//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;
function GetEditHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
//找到发消息的目标窗口的目标控件
if StrPas(Buffer)='Edit' then
begin
GetWindowText(hwnd,buffer1,100);
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;//end of function
发送信息部分
判断为空
SendMessage(FTextHandle, WM_GETTEXT, 1024, Integer(@Buf));
s:= buf;
if ((Length(s)<>0) and (IsWindowEnabled(FButtonHandle)=false)) then
begin
Exit;
end;
模拟发送信息
SendMessage(FTextHandle,WM_SETTEXT,0,Integer(pchar(sSend)));
模拟按钮单击信息发送按钮
SendMessage(FButtonHandle,WM_LBUTTONDOWN,0,0);
SendMessage(FButtonHandle,WM_LBUTTONUP,0,0);
结束啦,基本上就这些。