Delphi编程:QQ聊天记录怎样被记录下来(4)
中华网科技 http://tech.china.com
2005-07-25 10:37:44
|
|
|
//窗口消息处理过程
procedure TForm1.WndProc(var Msg: TMessage);
begin
with Msg do
begin
if Msg = WM_USERCMD then //DLL发来的自定义消息
begin
case wParam of
UC_WINCREATE : //QQ消息框创建
begin
GetText(Findhwd(HWND(lParam))); //得到QQ消息框里的文本
end;
end;
end;
end;
inherited;
end;
//通过wParam参数找到QQ窗口句柄
function TForm1.Findhwd(parent: HWND):HWND;
var
hwd,hBtn,hMemo:HWND;
begin
result := 0;
hwd:=findwindowex(parent,0,‘#32770‘,nil); //QQ次级窗口句柄QQ2003及以前版本没有此项.
if (hwd<>0) then
begin
hBtn := FindwindowEX(hwd,0,nil,‘回讯息(&R)‘); //可以以此来证明是收到的QQ消息框.
if (hBtn<>0) then
begin
hMemo := GetDlgItem(hwd,$00000380); //RichEdit的句柄,QQ消息就存在于此处.
if (hMemo<>0) then
result := hMemo;
end;
end;
end;
//得到指定句柄控件中的文本.
procedure TForm1.GetText(hwd: HWND);
var
Ret: LongInt;
QQText: PChar; Buf: integer;
begin
GetMem(QQText,1024);
if (hwd<>0) then
begin
try
Ret := SendMessage(hwd, WM_GETTEXTLENGTH, 0, 0) + 1;
Buf := LongInt(QQText);
SendMessage(hwd, WM_GETTEXT, Min(Ret, 1024), Buf);
memo1.Lines.Add(QQText); //在Memo中显示文本
finally
FreeMem(QQText, 1024);
end;
end;
end;
首页 上页 | ...1| 2 | 3 | 4 | 下页 尾页 共 4 页
|