高分求解:怎样得到正在执行的程序中ListView中的内容---急急急急急(200分)

  • 主题发起人 主题发起人 illcat
  • 开始时间 开始时间
《Windows核心编程》里面有个跨进程SubClass的例子,恰好就是用的ListView<br>如果有这本书的话建议看看
 
月满西楼兄能否贴出核心代码?<br>
 
书不在这里,晚上再说吧
 
满复杂的,我自己写个Demo结果把资源管理器Crash掉了。目前没有时间研究了,<br>代码太长也懒得打字,如果你真的需要我就把Jeffrey Richter的程序发给你,<br>不过没有书配合着看恐怕效果不会好。
 
我用WH_CALLWNDPROC钩子终于可以钩到LVM_SETITEMTEXT消息了,但是程序还是有问题,我<br>把代码贴出来,大家看看,对了,说明一下,我是要取得QQ企业版的通话记录。<br><br>unit HKProc; <br><br>interface <br><br>uses <br>&nbsp; &nbsp; &nbsp; &nbsp; Windows, Messages, CommCtrl;<br><br>var <br>&nbsp; &nbsp; &nbsp; &nbsp; hNextHookProc: HHook;<br>&nbsp; &nbsp; &nbsp; &nbsp; procSaveExit: Pointer;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; function WndProcHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;<br>&nbsp; &nbsp; &nbsp; &nbsp; function EnableWndProcHook: BOOL; export;<br>&nbsp; &nbsp; &nbsp; &nbsp; function DisableWndProcHook: BOOL; export;<br>&nbsp; &nbsp; &nbsp; &nbsp; procedure WndProcHookExit; far;<br><br>implementation <br><br>function WndProcHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;<br>var<br>&nbsp; &nbsp; &nbsp; &nbsp; hd : HWND;<br>&nbsp; &nbsp; &nbsp; &nbsp; ChildHd: HWND;<br>&nbsp; &nbsp; &nbsp; &nbsp; ExportFile: TextFile;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; if iCode &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>////////////////////////////////////////////////////////////////////////<br>//取得QQ消息管理器中的ListView的句柄<br>/////////////////////////////////////////////////////////////////////////<br>&nbsp; &nbsp; &nbsp; &nbsp; hd := FindWindow(nil, '消息管理器');<br>&nbsp; &nbsp; &nbsp; &nbsp; if hd &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChildHd := GetWindow(hd, GW_CHILD);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChildHd := GetWindow(ChildHd, GW_CHILD);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChildHd := GetWindow(ChildHd, GW_CHILD);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp;/////////////////////////////////////////////////////////////////////<br>&nbsp; &nbsp; &nbsp; &nbsp; if (PCWPSTRUCT(lParam).hwnd = ChildHd) and (PCWPSTRUCT(lParam).message = LVM_SETITEMTEXT) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result := 1;<br>////////////////////////////////////////////////////////////////////////////<br>//把LVM_SETITEMTEXT中的lParam导出,并存为文件<br>//在执行到Append这一句的时候QQ出了一个错,异常退出了,如果把Append<br>//改为Rewrite则正常,不解?望大侠们指点迷津<br>///////////////////////////////////////////////////////////////////////////<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AssignFile(ExportFile, 'd:/test.txt');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Append(ExportFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Writeln(ExportFile, PLVITEM(PCWPSTRUCT(lParam).lParam).pszText);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Flush(ExportFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseFile(ExportFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //MessageBox(0,'now has Appended File','',0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>end;<br><br>function EnableWndProcHook: BOOL; export;<br>begin <br>&nbsp; &nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; hNextHookProc := SetWindowsHookEx(WH_CALLWNDPROC, WndProcHookHandler, HInstance, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := hNextHookProc &lt;&gt; 0;<br>end; <br><br>function DisableWndProcHook: BOOL; export;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := hNextHookProc = 0;<br>end; <br><br>procedure WndProcHookExit;<br>begin <br>&nbsp; &nbsp; &nbsp; &nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DisableWndProcHook;<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitProc := procSaveExit; <br>end; <br><br>end.<br><br>源码基本都是抄大富翁的,中间我的一段代码总出问题,大家看看注释,谢谢!<br><br>附WndProc.dpr<br>library WndProc;<br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; HKProc in 'HKProc.pas';<br><br>exports <br>&nbsp; &nbsp; &nbsp; &nbsp; EnableWndProcHook,<br>&nbsp; &nbsp; &nbsp; &nbsp; DisableWndProcHook;<br><br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; procSaveExit := ExitProc;<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitProc := @WndProcHookExit;<br>end.<br>
 
大家伸伸援助之手吧,有什么要求可以提嘛
 
求人不如求己啊,终于搞定,散分散分,<br>DoubleWood你的建议很重要,西西,多谢<br>月兄,如果你有你说的原码,麻烦寄给小弟研读一下,谢谢!
 
我很菜,说错了话大家不要笑啊。用FindControl(Hwnd)不是可以得到组件吗?
 
zhuazhua@sina.com,谢谢月满西楼大侠
 
后退
顶部