www.demi-s.narod.ru

Delphi
Статьи:

· Интерфейс

· WinAPI

· Компоненты

· Базы данных

· ShellAPI



WinAPI


Получить текст из панели состояния

Два примера демонстрируют, как получить текст панели состояния из других приложений.

{ 1. Работает только для первой панели строки состояния в другом процессе }


function GetStatusText(wndWindow: THandle; 
  StatusBarClassName: string; 
  PanelIndex: Byte): string; 
var
  WndStatusBar: THandle; 
  StatusBarText: array[0..$FFF] of Char;
begin
  Result := ''; 
  WndStatusBar := FindWindowEx(wndWindow, 0, PChar(StatusBarClassName), nil);
  if WndStatusBar <> 0 then
  begin
    if PanelIndex = 0 then
      SendMessage(WndStatusBar, WM_GETTEXT, $FFF, Longint(@StatusBarText))
    else
      SendMessage(WndStatusBar, SB_GETTEXT, PanelIndex, Longint(@StatusBarText));
    Result := StrPas(StatusBarText);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // Читаем текст строки состояния из Internet Explorer 
  label1.Caption := GetStatusText(FindWindow('IEFrame', nil), 'msctls_statusbar32', 0); 
  // Также работает с TStatusBar 
  Label2.Caption := GetStatusText(Form1.Handle, 'TStatusBar', 0); 
end;
{ 2. 
    Для чтения панели состоняния в другом процессе, используйте эту функцию:
    Работает со всеми Statusbar Panels
}

uses
  CommCtrl, uProcessMemMgr { из Download }; 


function GetStatusBarText(hStatusBarHandle: HWND; PanelNumber: Integer): string; 
var
  PMM: TProcessMemMgr; 
  NumberOfPanels, Len: Integer; 
  PrcBuf: PChar; 
  PartText: string; 
begin
  if hStatusBarHandle = 0 then Exit;
  PMM := CreateProcessMemMgrForWnd(hStatusBarHandle);
  try
    NumberOfPanels := SendMessage(hStatusBarHandle, SB_GETPARTS, 0, 0); 
    if PanelNumber < NumberOfPanels then
    begin
      Len := LOWORD(SendMessage(hStatusBarHandle, SB_GETTEXTLENGTH, PanelNumber, 0)); 
      if Len > 0 then
      begin
        PrcBuf := PMM.AllocMem(Len + 1); 
        SendMessage(hStatusBarHandle, SB_GETTEXT, PanelNumber, Longint(PrcBuf)); 
        Result := PMM.ReadStr(PrcBuf); 
        PMM.FreeMem(PrcBuf); 
      end
      else 
      begin
        Result := ''; 
      end;
    end; 
  finally
    PMM.Free; 
  end;
end;

// Пример читает текст строки состояния из explorer.exe 
procedure TForm1.Timer1Timer(Sender: TObject);
var
  hWindow, hStatusBarHandle: HWND; 
begin
  hWindow := FindWindow('ExploreWClass', nil);
  if FensterHandle = 0 then Exit;
  hStatusBarHandle := FindWindowEx(hWindow, 0, 'msctls_statusbar32', nil);
  label1.Caption := GetStatusBarText(hStatusBarHandle, 2);
end;

Hosted by uCoz