我用WH_CALLWNDPROC钩子终于可以钩到LVM_SETITEMTEXT消息了,但是程序还是有问题,我<br>把代码贴出来,大家看看,对了,说明一下,我是要取得QQ企业版的通话记录。<br><br>unit HKProc; <br><br>interface <br><br>uses <br> Windows, Messages, CommCtrl;<br><br>var <br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br><br> function WndProcHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;<br> function EnableWndProcHook: BOOL; export;<br> function DisableWndProcHook: BOOL; export;<br> procedure WndProcHookExit; far;<br><br>implementation <br><br>function WndProcHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;<br>var<br> hd : HWND;<br> ChildHd: HWND;<br> ExportFile: TextFile;<br>begin<br> Result := 0;<br> if iCode < 0 then<br> begin<br> Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br> Exit;<br> end;<br>////////////////////////////////////////////////////////////////////////<br>//取得QQ消息管理器中的ListView的句柄<br>/////////////////////////////////////////////////////////////////////////<br> hd := FindWindow(nil, '消息管理器');<br> if hd <> 0 then<br> begin<br> ChildHd := GetWindow(hd, GW_CHILD);<br> ChildHd := GetWindow(ChildHd, GW_CHILD);<br> ChildHd := GetWindow(ChildHd, GW_CHILD);<br> end;<br> /////////////////////////////////////////////////////////////////////<br> if (PCWPSTRUCT(lParam).hwnd = ChildHd) and (PCWPSTRUCT(lParam).message = LVM_SETITEMTEXT) then<br> begin<br> result := 1;<br>////////////////////////////////////////////////////////////////////////////<br>//把LVM_SETITEMTEXT中的lParam导出,并存为文件<br>//在执行到Append这一句的时候QQ出了一个错,异常退出了,如果把Append<br>//改为Rewrite则正常,不解?望大侠们指点迷津<br>///////////////////////////////////////////////////////////////////////////<br> AssignFile(ExportFile, 'd:/test.txt');<br> Append(ExportFile);<br> Writeln(ExportFile, PLVITEM(PCWPSTRUCT(lParam).lParam).pszText);<br> Flush(ExportFile);<br> CloseFile(ExportFile);<br> //MessageBox(0,'now has Appended File','',0);<br> end;<br>end;<br><br>function EnableWndProcHook: BOOL; export;<br>begin <br> Result := False;<br> if hNextHookProc <> 0 then<br> Exit;<br><br> hNextHookProc := SetWindowsHookEx(WH_CALLWNDPROC, WndProcHookHandler, HInstance, 0);<br> Result := hNextHookProc <> 0;<br>end; <br><br>function DisableWndProcHook: BOOL; export;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> UnhookWindowshookEx(hNextHookProc);<br> hNextHookProc := 0;<br> end;<br> Result := hNextHookProc = 0;<br>end; <br><br>procedure WndProcHookExit;<br>begin <br> if hNextHookProc <> 0 then<br> DisableWndProcHook;<br> ExitProc := procSaveExit; <br>end; <br><br>end.<br><br>源码基本都是抄大富翁的,中间我的一段代码总出问题,大家看看注释,谢谢!<br><br>附WndProc.dpr<br>library WndProc;<br>uses<br> SysUtils,<br> Classes,<br> HKProc in 'HKProc.pas';<br><br>exports <br> EnableWndProcHook,<br> DisableWndProcHook;<br><br>begin<br> hNextHookProc := 0;<br> procSaveExit := ExitProc;<br> ExitProc := @WndProcHookExit;<br>end.<br>