(*//
标题:获取其他进程中StatisBar的文本
说明:Window2000+Delphi6调试通过
设计:Zswang
支持:[email protected]
日期:2005-02-22
//*)
uses CommCtrl;
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; { GetStatusBarText }
//Example
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, 1, MOD_WIN, VK_F2);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, 1);
end;
procedure TForm1.WMHOTKEY(var Msg: TWMHOTKEY);
begin
case Msg.HotKey of
1: Edit1.Text := GetStatusBarText(
WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y)));
end;
end;
本文地址:http://com.8s8s.com/it/it4304.htm