16,471
社区成员
发帖
与我相关
我的任务
分享
bool GetLvItemText(HWND Lv, int Index, int SubItem, CString& Text)
{
const int bufferLength = 4000;
bool result = false;
DWORD processId = NULL;
GetWindowThreadProcessId(Lv, &processId);
if (processId == NULL) return false;
HANDLE process = ::OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, FALSE, processId);
if (process == NULL) return false;
PVOID buffer = VirtualAllocEx(process, NULL, bufferLength, MEM_COMMIT, PAGE_READWRITE);
if (buffer != NULL)
{
LPLVITEM item = (LPLVITEM)new BYTE[bufferLength];
item->mask = LVIF_TEXT;
item->iSubItem = SubItem;
item->pszText = (LPTSTR)((PBYTE)buffer+sizeof(LVITEM));
item->cchTextMax = (bufferLength - sizeof(LVITEM)) / sizeof(TCHAR);
WriteProcessMemory(process, buffer, item, sizeof(LVITEM), NULL);
if (SendMessage(Lv, LVM_GETITEMTEXT, Index, (LPARAM)buffer) != 0)
{
ReadProcessMemory(process, buffer, item, 1024, NULL);
Text = (LPTSTR)((PBYTE)item+sizeof(LVITEM));
result = true;
}
delete item;
VirtualFreeEx(process, buffer, sizeof(LVITEM), MEM_DECOMMIT);
}
CloseHandle(process);
return result;
}