如何访问另一个正在运行的程序的ListView中各单元格的内容?(88分)

Y

yhee

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在使用Findwindow和SendMessage配合,可以得到ListView中Item的条数,也能够
清除各行,但是就是不能使用LVM_GETITEM获取各单元格的内容.
因为急用,请高手出手相救.
 
用钩子函数
 
var
Item: TLVItem;
begin
with Item do
begin
mask := LVIF_PARAM;
iItem := Index;
iSubItem := 0;
end;
SendMessage(hWnd, LVM_GETITEM, 0, Longint(@Item);
result:=TListItem(Item.lParam);
end;
 
yhee,有什么办法了吗(scxby的方法只能用于同一进程)?
谁能解决这个问题,我愿出500分。
 
[h1]up[/h1]
 
再次告诉你:“用钩子函数”
你要编一个dll用setwindowshook注入到目标进程中。
 
已经解决,不过我是用C写的一个函数,需要的话请站内发信。
 
to yhee,帖出来吧~
 
//Written in C Language

int RListView_GetItemText_Remote(HWND hwndLV,int nItem,int nSubItem,LPSTR szText,int nTextLen)
{

*szText=0;

// If the window under the cursor isn't a ListView, we have nothing to do.
if (hwndLV == NULL)
return 0;

// Open a handle to the remote process's kernel object
DWORD dwProcessId;
GetWindowThreadProcessId(hwndLV, &dwProcessId);
HANDLE hProcess = OpenProcess(
PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
FALSE, dwProcessId);

if (hProcess == NULL) {
// MessageBox(hwnd, __TEXT("Could not communicate with process"),
// g_szAppName, MB_OK | MB_ICONWARNING);
return 0;
}

// Prepare a buffer to hold the ListView's data.
// Note: Hardcoded maximum of 10240 chars for clipboard data.
// Note: Clipboard only accepts data that is in a block allocated with
// GlobalAlloc using the GMEM_MOVEABLE and GMEM_DDESHARE flags.
HGLOBAL hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
sizeof(TCHAR) * 10240);
LPTSTR pClipData = (LPTSTR) GlobalLock(hClipData);
pClipData[0] = 0;

// Allocate memory in the remote process's address space
LV_ITEM* plvi = (LV_ITEM*) VirtualAllocEx(hProcess,
NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

// Get each ListView item's text data

// Initialize a local LV_ITEM structure
LV_ITEM lvi;
lvi.mask = LVIF_TEXT;
lvi.iItem = nItem;
lvi.iSubItem = nSubItem;
// NOTE: The text data immediately follows the LV_ITEM structure
// in the memory block allocated in the remote process.
lvi.pszText = (LPTSTR) (plvi + 1);
lvi.cchTextMax = 100;

// Write the local LV_ITEM structure to the remote memory block
WriteProcessMemory(hProcess, plvi, &lvi, sizeof(lvi), NULL);

// Tell the ListView control to fill the remote LV_ITEM structure
ListView_GetItem(hwndLV, plvi);

// Read the remote text string into the end of our clipboard buffer
ReadProcessMemory(hProcess, plvi + 1,
pClipData, 1024, NULL);

// Free the memory in the remote process's address space
VirtualFreeEx(hProcess, plvi, 0, MEM_RELEASE);

// Cleanup and put our results on the clipboard
CloseHandle(hProcess);
strcpy(szText,pClipData);

return strlen(szText);
}
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
817
DelphiTeacher的专栏
D
D
回复
0
查看
851
DelphiTeacher的专栏
D
顶部