How to read the statusbar contents of Internet Explorer

Started by José Roca, August 29, 2011, 12:18:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
This example finds the handle of a running instance of Internet Explorer, enumerates its child windows to find the handle of the status bar and retrieve the text of the first part of it.

Note Since version 9, Internet Explorer no longer has an status bar.


' ########################################################################################
' This example finds the handle of a running instance of Internet Explorer, enumerates
' its child windows to find the handle of the status bar and retrieve the text of the
' first part of it.
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
%UNICODE = 1
#INCLUDE "commctrl.inc"

' ========================================================================================
' Callback for EnumChildWindows
' ========================================================================================
FUNCTION EnumChildProc(BYVAL hwnd AS DWORD, BYVAL lParam AS DWORD PTR) AS LONG

   LOCAL wszClassName AS WSTRINGZ * %MAX_PATH
   GetClassName(hwnd, wszClassName, %MAX_PATH)
   IF wszClassName = "msctls_statusbar32" THEN
      IF lParam <> %NULL THEN @lParam = hWnd
      FUNCTION = %FALSE
   ELSE
      FUNCTION = %TRUE
   END IF

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL hWndExplorer AS DWORD                   ' // Internet Explorer handle
   LOCAL hStatusbar AS DWORD                     ' // Status bar handle
   LOCAL hProc AS DWORD                          ' // Process handle
   LOCAL dwProcID AS DWORD                       ' // Process identifier
   LOCAL pMem AS DWORD                           ' // Virtual memory address
   LOCAL nLen AS LONG                            ' // Text length
   LOCAL buffer AS STRING                        ' // General purpose string buffer
   LOCAL dwResult AS DWORD                       ' // Result code
   LOCAL cbRead AS DWORD                         ' // Bytes read

   ' // Find the window handle of a running instance of Internet Explorer
   hWndExplorer = FindWindow("IEFrame", BYVAL %NULL)
   IF ISFALSE hWndExplorer THEN
      ? "Internet Explorer isn't running"
      EXIT FUNCTION
   END IF
   ' // Enumerate its child windows
   EnumChildWindows hWndExplorer, CODEPTR(EnumChildProc), VARPTR(hStatusbar)
   ' // If found...
   IF hStatusbar THEN
      ' // Retrieve the text length of the first part (0 based)
      dwResult = SendMessage (hStatusBar, %SB_GETTEXTLENGTH, 0, 0)
      nLen = LO(WORD, dwResult)
      ' // Allocate an string buffer
      buffer = SPACE$((nLen + 1))
      ' // Retrieve the process identifier
      GetWindowThreadProcessID(hStatusBar, dwProcID)
      ' // Retrieve the process handle
      ' // Note For Windows Vista it should be:
      ' hProc = OpenProcess(%STANDARD_RIGHTS_REQUIRED OR %SYNCHRONIZE OR &HFFFF, 0, dwProcID)
      hProc = OpenProcess(%STANDARD_RIGHTS_REQUIRED OR %SYNCHRONIZE OR &H0FFF, 0, dwProcID)
      ' // Allocate memory
      pMem = VirtualAllocEx(hProc, BYVAL %NULL, LEN(buffer), %MEM_COMMIT, %PAGE_READWRITE)
      ' // Retrieve the text
      dwResult = SendMessage(hStatusBar, %SB_GETTEXT, 0, pMem)
      ' // Read process memory
      ReadProcessMemory(hProc, pMem, BYVAL STRPTR(buffer), LEN(buffer), cbRead)
      ' // Remove the ending null character
      IF cbRead THEN buffer = LEFT$(buffer, cbRead - 1)
      ' // Release memory
      dwResult = VirtualFreeEx(hProc, BYVAL pMem, 0, %MEM_RELEASE)
      ' // Close process handle
      IF hProc THEN CloseHandle hProc
      ' // Display the string
      ? buffer
   ELSE
      ? "Status bar not found"
   END IF

END FUNCTION
' ========================================================================================

  •