闲来无聊之作品,愿与大家探讨交流,共同进步!
//取QQ版本信息函数
function ReadQQRegInf: boolean;
Var
regRegistry : TRegistry;
begin
result := True;
regRegistry := TRegistry.Create;
try
try
regRegistry.RootKey := HKEY_LOCAL_MACHINE;
if regregistry.OpenKey('/SOFTWARE/Tencent/QQ',true) then
begin
gsQQInstall := regregistry.ReadString('Install');
gsQQVersion := regregistry.ReadString('version');
end;
regregistry.CloseKey;
except
result := False;
end;
finally
regregistry.Free;
end;
end;
//发送事件处理
procedure TFrmMain.btnSendClick(Sender: TObject);
var
h, h2, hChild, hChild2, hBtn: THandle;
Buf: array[0..1024] of Char;
i: integer;
s, sPwd: string;
begin
s := memosendMeg.Text;
h := FindWindow(nil, pchar('与 '+cbFName.text+' 聊天中'));
RichEdit1.Lines.Add(IntToHex(h, 8));
if h=0 then
begin
Application.MessageBox('请确认与好友的聊天界面已打开,并进入【消息模式】!',
'错误', MB_OK+MB_ICONWARNING);
exit;
end;
hChild := FindWindowEx(h, 0, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild, 8));
hChild := FindWindowEx(h, hChild, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild, 8));
hChild := FindWindowEx(h, hChild, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild, 8));
hChild := FindWindowEx(h, hChild, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild, 8));
h := hChild;
hChild2 := FindWindowEx(h, 0, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild2, 8));
hChild2 := FindWindowEx(h, hChild2, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild2, 8));
//QQ2006官方正式版V06.0.200.370以下版本处理
if StrtoFloat(gsQQVersion)<1595.370 then
begin
hChild2 := FindWindowEx(h, hChild2, nil, '');
RichEdit1.Lines.Add(IntToHex(hChild2, 8));
end;
//如果是珊瑚虫版可以取到ip地址信息
h2 := hChild2;
hChild2:=GetWindow(h2,gw_hwndfirst);
RichEdit1.Lines.Add(IntToHex(hChild2, 8));
SendMessage(hChild2, WM_GETTEXT, 1024, Integer(@Buf));
RichEdit1.Lines.Add(Buf);
//取QQ号码信息
hChild2 := FindWindowEx(h, h2, nil, Buf);
//QQ2007Beta1 V07.0.101.162以上版本处理
if StrtoFloat(gsQQVersion)>=1631.160 then
begin
hChild2 := FindWindowEx(h, h2, nil, '');
hChild2 := FindWindowEx(h, h2, nil, '');
end;
h2 := GetWindow(hChild2, GW_CHILD);
hChild2:=GetWindow(h2,gw_hwndfirst);
RichEdit1.Lines.Add(IntToHex(hChild2, 8));
SendMessage(hChild2, WM_GETTEXT, 1024, Integer(@Buf));
RichEdit1.Lines.Add(Buf);
if pos('(XXXXXXX)', Buf) > 0 then
begin
//这里对想要屏蔽的QQ号处理
exit;
end;
//"发送"按钮句柄
hBtn := FindWindowEx(h, 0, 'Button', '发送(S)');
RichEdit1.Lines.Add(IntToHex(hBtn, 8));
hChild := FindWindowEx(h, hBtn, 'AfxWnd42', '');
RichEdit1.Lines.Add(IntToHex(hChild, 8));
h := hChild;
//QQ2006官方正式版V06.0.200.370以上版本处理
if StrtoFloat(gsQQVersion)>=1595.370 then
hChild := FindWindowEx(h, 0, 'RichEdit20A', '')
else
hChild := FindWindowEx(h, 0, 'RICHEDIT', ''); //默认处理
RichEdit1.Lines.Add(IntToHex(hChild, 8));
//向输入框中加入尾巴
SendMessage(hChild, EM_REPLACESEL, 1, integer(pchar(s)));
SendMessage(hBtn, WM_LBUTTONDOWN, 0, 0);
SendMessage(hBtn, WM_LBUTTONUP, 0, 0);
end;