获取其他进程中StatusBar的文本

时间:2010-01-27 16:31:57  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: />说明:Window2000+Delphi6调试通过设计:Zswang支持:wjhu111@21cn.com日期:2005-02-22//*)uses CommCtrl;function GetStatusBarText(mHandle: THandle): string;varvBuffer: array[0..$1000] of Char;vSize: Integer;I: Integer;vCount: Integer;vProcessId: DWORD;vProcess: ...
  正文:请看下面的单元代码:


(*//
标题:获取其他进程中StatusBar的文本
说明:Window2000+Delphi6调试通过
设计:Zswang
支持:wjhu111@21cn.com
日期: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;

"获取其他进程中StatusBar的文本"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/2010-01-27/12511.html


关键字:

关于《获取其他进程中StatusBar的文本》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td