B
bo717
Unregistered / Unconfirmed
GUEST, unregistred user!
我用以下函数可以得到某文件夹里的文件列表,那我要得到里边被选中的文件的名称要怎么做呢?function ListViewColumnCount(mHandle: THandle): Integer; begin Result := Header_GetItemCount(ListView_GetHeader(mHandle)); end; { ListViewColumnCount } function GetListViewText(mHandle: THandle; mStrings: TStrings): Boolean; var vColumnCount: Integer; vItemCount: Integer; I, J: Integer; vBuffer: array[0..255] of Char; vProcessId: DWORD; vProcess: THandle; vPointer: Pointer; vNumberOfBytesRead: Cardinal; S: string; vItem: TLVItem; begin Result := False; if not Assigned(mStrings) then Exit; vColumnCount := ListViewColumnCount(mHandle); if vColumnCount <= 0 then Exit; vItemCount := ListView_GetItemCount(mHandle); GetWindowThreadProcessId(mHandle, @vProcessId); vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, vProcessId); vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); mStrings.BeginUpdate; try mStrings.Clear; for I := 0 to vItemCount - 1 do begin S :=''; for J := 0 to vColumnCount - 1 do begin with vItem do begin mask := LVIF_TEXT; iItem := I; iSubItem := J; cchTextMax := SizeOf(vBuffer); pszText := Pointer(Cardinal(vPointer) + SizeOf(TLVItem)); end; WriteProcessMemory(vProcess, vPointer, @vItem, SizeOf(TLVItem), vNumberOfBytesRead); SendMessage(mHandle, LVM_GETITEM, 0, lparam(vPointer)); ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)), @vBuffer[0], SizeOf(vBuffer), vNumberOfBytesRead); S := S + #9 + vBuffer; end; Delete(S, 1, 1); mStrings.Add(S); mStrings.Add(inttostr(vItemCount)); end; finally VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE); CloseHandle(vProcess); mStrings.EndUpdate; end; Result := True; end;调用: GetListViewText( WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y)), Memo1.Lines);