Title: Get the Text of a Statusbar Panel
Question: The following example shows how to retreive the Text of a Statusbar Panel (example 2 even of another process)
Answer:
{ 1. Works only for the first Statusbar Panel in another process }
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:
Works for all Statusbar Panels
}
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 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
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;