whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

39 Visitors Online


 
...get the text of a StatusBar?
Autor: Thomas Stutz
[ Print tip ]  


Tip Rating (14):  
     


{ 1.
    Works only for the first Panel in another process
    Funktioniert nur beim 1.Panel in einem anderen Prozess
}


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
  
// Read statustext from Internet Explorer
  
label1.Caption := GetStatusText(FindWindow('IEFrame', nil), 'msctls_statusbar32', 0);
  // Also works with a TStatusBar
  
Label2.Caption := GetStatusText(Form1.Handle, 'TStatusBar', 0);
end;


{***************************************************}

{ 2.
    To Read the statusbar in another process, use this function:
    Damit kann man auch in einem anderen Prozess den Statusbar Text bei Subpanels auslesen
}

uses
  
CommCtrl, uProcessMemMgr { from 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;

// Example to read the statusbar text of the explorer.exe
// Beispiel, um den Statusbar text des explorers auszulesen
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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners