如题
如果你在专家前给出代码,或者专家给不出代码,你先给出.500分奉上=5个帖子的总和
如果某个专家给出代码,我将补齐500分给你.
在qq的聊天窗口,当按下"发送"按钮之前,执行一段我的代码 
希望能用全局消息钩子加子类化函数实现 
WH_CALLWNDPROC setwindowslong 
因为,用全局钩子消息,我已会 我在学子类化函数的用法? library TmHook; uses 
  SysUtils, 
  Classes, 
  Windows, 
  Messages, 
  CommCtrl; 
var 
  hhook: Windows.HHOOK; 
  hwndListView: HWND; 
  na:array[0..300] of char; 
  oldWndProc: Integer; 
{$R *.res} 
function WindowProc(hwnd: HWND; msg: UINT; wp: WPARAM; lp: LPARAM): LRESULT; stdcall; 
  begin 
  case Msg of 
    WM_LBUTTONDOWN: 
    MessageBox(hwndListView,'你好!','提示',MB_OK); 
  end; 
  Result := CallWindowProc(TFNWndProc(oldWndProc), hwnd, msg, wp, lp); 
end; 
function TmHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): Integer; stdcall; 
var 
  cwp: PCwpStruct; 
  m:TPoint; 
begin 
  Result := 0; 
  if (nCode < 0) then 
  begin 
    Result := CallNextHookEx(hhook, nCode, wParam, lParam); 
    exit; 
  end; 
  cwp := PCwpStruct(lParam); 
  if cwp^.message <> WM_COMMAND then 
  begin 
    Result := CallNextHookEx(hhook, nCode, wParam, lParam); 
    exit; 
  end; 
  GetCursorPos(m); 
  GetWindowText(WindowFromPoint(m),na,299); 
  if lstrcmpi('发送(S)',na) <>0 then 
  begin 
    Result := CallNextHookEx(hhook, nCode, wParam, lParam); 
    exit; 
  end; 
  hwndListView:=WindowFromPoint(m); 
  oldWndProc := SetWindowLong(hwndListView, GWL_WNDPROC, Integer(@WindowProc)); 
  end; 
procedure Hook(bEnable: Boolean); stdcall; export; 
begin 
  if bEnable then 
  begin 
    if hhook = 0 then 
    begin 
      hhook := SetWindowsHookEx(WH_CALLWNDPROC, TmHookProc, HInstance, 0); 
    end; 
  end 
  else 
  begin 
    if hhook <> 0 then 
    begin 
      UnhookWindowsHookEx(hhook); 
      hhook := 0; 
    end; 
  end; 
end; 
exports 
  Hook; 
begin 
  hhook := 0; 
  hwndListView := 0; 
  oldWndProc:=0; 
end. 
到底哪里错了,一运行,qq就自动关闭?? 

解决方案 »

  1.   


    还好意思说,全局钩子不是我写出来,你会个啥?
    在钩子中用WindowFromPoint(m)是非常不应该的,失去了WH_CALLWNDPROC的意义。还不如用无DLL的鼠标钩子。
    子类化非常容易,关键是你要找到切入点。QQ聊天时很多人都不是用鼠标去点“发送”按扭的,比如用Alt+S来发消息,你的全局钩子根本钩不住,除非你把鼠标放到按扭上单击。要实现钩住发送消息根本不是这样做的。
      

  2.   

    http://topic.csdn.net/u/20081118/16/2fb814e9-76af-4883-8e81-9b599bb83ebc.html?seed=1656828274