4 Replies - 2161 Views - Last Post: 11 May 2013 - 05:53 PM Rate Topic: -----

#1 Demix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-May 13

Get Status Bar Text from External App

Posted 11 May 2013 - 03:04 PM

Hello there,

I'm having a few issues trying to pull text from a status bar of an external program. Long story short, if anyone has heard of Open Broadcasting Software, at the bottom of the program it shows exactly how long your stream has been "live" within a status bar. I just need a way to pull this out so I can save it to a text file. So far I've managed to find the window using Spy++ and using SendMessage I've been able to find how many "parts" the status bar has but beyond that i'm having no joy. Here's what I have:

        For Each p As Process In Process.GetProcessesByName("OBS")
            Dim hOBS As IntPtr = IntPtr.Zero
            hOBS = FindWindow("OBSWindowClass", vbNullString)
            If hOBS = IntPtr.Zero Then
                MsgBox("Open Broadcaster Software is not running.")
                Exit Sub
            End If
            MsgBox(hOBS)
            Dim bag As IntPtr = FindWindowEx(hOBS, New IntPtr(0), "msctls_statusbar32", vbNullString) ' sets intLength as an int equal to the spotify windows title length
            MsgBox(bag)

            Dim nParts As String
            nParts = SendMessage(bag, SB_GETPARTS, 0, 0)
            MsgBox(nParts)

            Dim nLength As String
            nLength = SendMessage(bag, SB_GETTEXTLENGTH, 0, 0)
            MsgBox(nLength)


I've also tried get GetWindowText but have been told it only works if the status bar is within the same app, which i couldn't figure out _ so gave it a go anyway.


            Dim lpText As String
            lpText = New String(Chr(0), 100)
            Dim intLength As Integer = GetWindowText(bag, lpText, lpText.Length)
            Dim strTitle As String = lpText
            MsgBox(strTitle)


Oh I have all the FindWindow and FindWindowEx functions defined correctly and whatnot. And -
    Const WM_USER = &H400&
    Const WM_GETTEXT As Integer = &HD
    Const SB_GETTEXTLENGTH = (WM_USER + 3)
    Const SB_GETPARTS = (WM_USER + 6)
    Const SB_GETTEXT = (WM_USER + 2)


all set.. I've read somewhere it's something to do with sharing memory in order to pull the text from the external status bar but I was hoping there was a simpler method to do this. Any assistance would be appreciated. Thanks! If there's any more information needed I will do my best to supply it.

Is This A Good Question/Topic? 0
  • +

Replies To: Get Status Bar Text from External App

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3608
  • View blog
  • Posts: 12,393
  • Joined: 12-December 12

Re: Get Status Bar Text from External App

Posted 11 May 2013 - 04:04 PM

There is an API(?):

Quote

OBS has an API allowing developers to create their own unique plugins, giving them and others complete control of their streaming experience.

Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 321
  • View blog
  • Posts: 988
  • Joined: 01-February 13

Re: Get Status Bar Text from External App

Posted 11 May 2013 - 04:32 PM

Hi,
Try this little program i threw together. Just start your program and run this program. Hold your mouse over the statusbar and see if it shows you the text. If it does then you can get the text using the SendMessage API. The GetWindowText API is not as reliable as using the SendMessage API for getting text. All you need to do is make a new project and add 1 timer and 2 textboxes. You can see in the picture that i am holding the mouse over the statusbar on WordPad just for an example. You will probably have to find the handle to the main window and then use the FindWindowEx API to find the statusbar handle because it is probably a child of the main window. Then send the WM_GetText message to get the text from the statusbars handle.
Imports System.Runtime.InteropServices

Public Class Form1
    Const WM_GETTEXT As Integer = &HD
    Const WM_GETTEXTLENGTH As Integer = &HE
    Dim hControl As IntPtr = IntPtr.Zero

    <DllImport("user32.dll")> Private Shared Function WindowFromPoint(ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Int32, ByVal lParam As String) As Int32
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Timer1.Stop()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 200
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        hControl = WindowFromPoint(MousePosition.X, MousePosition.Y)
        Dim winclass As New System.Text.StringBuilder("", 256)
        GetClassName(hControl, winclass, 255)
        Dim titlelen As Integer = SendMessage(hControl, WM_GETTEXTLENGTH, 0, Nothing)
        Dim title As String = Space(titlelen + 1)
        SendMessage(hControl, WM_GETTEXT, titlelen + 1, title)
        TextBox2.Text = winclass.ToString
        TextBox1.Text = title
    End Sub

End Class


Attached Image

This post has been edited by IronRazer: 11 May 2013 - 04:38 PM

Was This Post Helpful? 1
  • +
  • -

#4 Demix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-May 13

Re: Get Status Bar Text from External App

Posted 11 May 2013 - 05:07 PM

Thank you very much IronRazer for the reply and the code! I ran the program and i've found that I can't get the text from the status bar which leads me to believe it is being drawn by the parent, thus rendering it unobtainable I guess.

and andrewsw, there is? That's something I overlooked.. I was too busy trying to be original and avoid external API's :P (I'm not a great programmer and API's still confuse me a tad) I will look into it and see if I can access said bit of text from their API.


View PostIronRazer, on 11 May 2013 - 04:32 PM, said:

Hi,
Try this little program i threw together. Just start your program and run this program. Hold your mouse over the statusbar and see if it shows you the text. If it does then you can get the text using the SendMessage API. The GetWindowText API is not as reliable as using the SendMessage API for getting text. All you need to do is make a new project and add 1 timer and 2 textboxes. You can see in the picture that i am holding the mouse over the statusbar on WordPad just for an example. You will probably have to find the handle to the main window and then use the FindWindowEx API to find the statusbar handle because it is probably a child of the main window. Then send the WM_GetText message to get the text from the statusbars handle.

Was This Post Helpful? 0
  • +
  • -

#5 Demix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-May 13

Re: Get Status Bar Text from External App

Posted 11 May 2013 - 05:53 PM

Just a quick reply,

I've looked into OBS's API and at the moment it has no documentation at all. In fact two of the things on the list of "stuff to be added to OBS soon" are;
API Documentation and "Some sort of .NET API interface for C#/VB developers" If anyone has any idea where in the API I should be looking then I would really appreciate it. Here's a link to the github for the project and the folder containing all things API related - https://github.com/j...e/master/OBSApi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1