当前位置: 首页 > 图文教程 > 开发语言 > Delphi > QQ聊天记录器演示程序(二)

Delphi
用Delphi 3.0编制MP3音乐点歌台
用Delphi制作动态有声标签
用Delphi4实现风Word97格的工具栏

Delphi 中的 QQ聊天记录器演示程序(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 149 ::
收藏到网摘: n/a

 
基于上篇《QQ聊天记录器演示程序(一)》,此文将讲述如何捕获自己发送出去的消息:

  // hottey   于2004-6-2号

  QQ从本机发出消息无非就是两种方式.(1)按发送按钮,(2)按Ctrl+Enter组合键.当然自定义键除外.也不在本文考虑范围之内:

  基于这两种发送的方式我选用:WH_CALLWNDPROC 和 WH_KEYBOARD两种钩子.Sorry,今天心情太烂(学校里的一些琐事,郁闷).实在无心继续.只能贴上源码了.大家有兴趣自己看看...有什么问题可以和我联系[email protected]


  //监控Ctrl+Enter组合键
function  KeyboardProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
    if (wParam = VK_RETURN) and (GetKeyState(VK_CONTROL) < 0) and (lParam >= 0) then
      begin
        SendMessage(Shared^.MainWnd,WM_USERCMD, UC_WINDESTROY, GetForegroundWindow);
      end;
      Result := CallNextHookEx(Shared^.KeyHook,iCode,wParam,lParam);
end;

//监控"发送"按钮
function CallWndProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
type
  Msg = ^CWPSTRUCT;
var
  p : Msg;
begin
  p := Msg(lParam);
//只对前台窗口进行处理
  if (p^.message = WM_COMMAND) and (LOWORD(p^.wParam) = 1) then
    begin
      SendMessage(Shared^.MainWnd,WM_USERCMD, UC_WINDESTROY, GetForegroundWindow);
    end;
  Result := CallNextHookEx(Shared^.CallHook,iCode,wParam,lParam);
end;


演示程序相关代码:


procedure TForm1.WndProc(var Msg: TMessage);
begin
 with Msg do
 begin
   if Msg = WM_USERCMD then
   begin
     case wParam of
       UC_WINDESTROY:
       begin
         GetText(Findhwd(HWND(lParam)));
       end;
     end;
   end;
 end;
 inherited;
end;






function TForm1.Findhwd(parent: HWND):HWND;
var
  hwd,hBtn,hMemo:HWND;
begin
    hwd:=findwindowex(parent,0,'#32770',nil);

    Result := 0;
    if (parent<>0) then
    begin
      hBtn := FindwindowEX(hwd,0,nil,'发送(&S)');
      if (hBtn<>0) then
        begin
          hMemo := GetDlgItem(hwd,$00000000);
          if (hMemo<>0) then
            begin
              result := GetWindow(hMemo,GW_CHILD);
            end;
        end;
    end;
end;


procedure TForm1.GetText(hwd: HWND);
var
  Ret: LongInt;
  QQText: PChar;
  Bu