Delphi获取其他进程中状态栏文本的函数
分类:Delphi
阅读 (2,107)
Add comments
9月 252012
Delphi code to get statusbar text from other process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
function GetStatusBarText(mHandle: THandle): string; var vBuffer: array[0..$1000] of Char; vSize: Integer; I: Integer; vCount: Integer; vProcessId: DWORD; vProcess: THandle; vPointer: Pointer; vNumberOfBytesRead: Cardinal; begin Result := ''; vCount := SendMessage(mHandle, SB_GETPARTS, 0, 0); if vCount <= 0 then Exit; GetWindowThreadProcessId(mHandle, @vProcessId); vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, vProcessId); vPointer := VirtualAllocEx(vProcess, nil, $1000, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); try for I := 0 to vCount - 1 do begin vSize := SendMessage(mHandle, SB_GETTEXT, I, 0) + 1; SendMessage(mHandle, SB_GETTEXT, I, Integer(vPointer)); ReadProcessMemory(vProcess, vPointer, @vBuffer[0], vSize, vNumberOfBytesRead); Result := Result + #9 + vBuffer; end; Delete(Result, 1, 1); finally VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE); CloseHandle(vProcess); end; end; |