楼上的好象搞错了吧?<br>花了近50分钟,搞了一下:<br>{***************************************************************<br> *<br> * Project Name: LittleCode -- uListViewInfo<br> * Typist: XJG(xianjun@163.net)<br> * Purpose: 使用读取进程内存的方式取得ListView的信息<br> * Comment Time: 2004-05-01 14:44:42<br> * History: Create by xjg. 2004-05-01 14:44:42<br> *<br> ****************************************************************}<br><br>unit uListViewInfo;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, uMDIAncestor, StdCtrls;<br><br>type<br> TForm3 = class(TFormMDIAncestor)<br> Memo1: TMemo;<br> Edit1: TEdit;<br> Button1: TButton;<br> Label1: TLabel;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>implementation<br><br>{$R *.dfm}<br><br>uses<br> CommCtrl;<br><br>const<br> Max_CaptionWidth = 512;<br><br>function GetListViewItemText(const AHwnd, AProcess: THandle; const pMemory: Pointer): string;<br>var<br> AItemCount, I, J, K: Integer;<br> S, ResName: string;<br> lvColumn: TLVColumn;<br> lvItem: TLVItem;<br> ASuccess: Boolean;<br> lpNumberOfBytesWritten: Cardinal;<br>begin<br> J := 0;<br> repeat<br> FillChar(lvColumn, SizeOf(lvColumn), 0);<br> lvColumn.Mask := LVCF_TEXT;<br> lvColumn.pszText := Pointer(Cardinal(pMemory) + SizeOf(lvColumn));<br> lvColumn.cchTextMax := Max_CaptionWidth;<br><br> WriteProcessMemory(AProcess, pMemory, @lvColumn, SizeOf(lvColumn), lpNumberOfBytesWritten);<br> ASuccess := Boolean(SendMessage(AHwnd, LVM_GETCOLUMN, J, LPARAM(pMemory)));<br> ReadProcessMemory(AProcess, pMemory, @lvColumn, SizeOf(TLVColumn), lpNumberOfBytesWritten);<br><br> SetLength(S, Max_CaptionWidth);<br> FillChar(Pointer(S)^, Max_CaptionWidth, 0);<br> ReadProcessMemory(AProcess, lvColumn.pszText, Pointer(S), lvColumn.cchTextMax, lpNumberOfBytesWritten);<br><br> if ASuccess and (StrLen(PChar(S)) > 0) then<br> if J = 0 then<br> ResName := PChar(S)<br> else<br> ResName := ResName + #09 + PChar(S);<br> Inc(J);<br> until not ASuccess;<br> Dec(J);<br> Result := ResName;<br><br> AItemCount := ListView_GetItemCount(AHwnd);<br> for I := 0 to AItemCount - 1 do<br> begin<br> for K := 0 to J - 1 do<br> begin<br> FillChar(lvItem, SizeOf(lvItem), 0);<br> lvItem.Mask := LVCF_TEXT;<br> lvItem.iSubItem := K;<br> lvItem.cchTextMax := Max_CaptionWidth;<br> lvItem.pszText := Pointer(Cardinal(pMemory) + SizeOf(lvColumn));<br><br> WriteProcessMemory(AProcess, pMemory, @lvItem, SizeOf(lvItem), lpNumberOfBytesWritten);<br> SendMessage(AHwnd, LVM_GETITEMTEXT, I, LPARAM(pMemory));<br> ReadProcessMemory(AProcess, pMemory, @lvItem, SizeOf(lvItem), lpNumberOfBytesWritten);<br> SetLength(S, Max_CaptionWidth);<br> FillChar(Pointer(S)^, Max_CaptionWidth, 0);<br> ReadProcessMemory(AProcess, lvItem.pszText, Pointer(S), lvItem.cchTextMax, lpNumberOfBytesWritten);<br><br> if K = 0 then<br> ResName := PChar(S)<br> else<br> ResName := ResName + #09 + PChar(S);<br> end;<br> Result := Result + #13#10 + ResName;<br> end;<br>end;<br><br>procedure TForm3.Button1Click(Sender: TObject);<br>var<br> hProcessID: DWORD;<br> hListView, hProcess: THandle;<br> pMemory: Pointer;<br>begin<br> hListView := StrToIntDef(Edit1.Text, 0);<br> GetWindowThreadProcessId(hListView, @hProcessID);<br> hProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or<br> PROCESS_VM_WRITE, False, hProcessID);<br> if hProcess = 0 then<br> RaiseLastOSError;<br> try<br> pMemory := VirtualAllocEx(hProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,<br> PAGE_READWRITE);<br> if pMemory = nil then<br> RaiseLastOSError;<br> try<br> Memo1.Text := GetListViewItemText(hListView, hProcess, pMemory);<br> finally<br> VirtualFreeEx(hProcess, pMemory, 0, MEM_RELEASE);<br> end;<br> finally<br> CloseHandle(hProcess);<br> end;<br>end;<br><br>end.<br><br>