Mega Code Archive

 
Categories / Delphi / VCL
 

How to get the text of a StatusBar

Title: How to get the text of a StatusBar 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: 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; Usage Example: // 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;