-
Jan 20th, 2014, 01:12 AM
#1
Thread Starter
Member
Retrieving information from another application
Okay I've done a lot of Google searching and I am at the point where I think I just need one extra nudge to point me in the right direction. I'm using a program called TheRecord Player. It an audio player associated with digital court recordings. On the program itself it has a child window with a caption of "Current playtime" and a Class name "Static" Now I've got the code up to the point where the GETTEXT returns "Current playtime" But of course I don't want Current Playtime returned, I want the actual time that's shown in that Class name Static. I'm just not sure if it's possible to grab the current time from that window or not. Here's what I have:
Public Class Form1
Private Declare Function IsWindowVisible Lib "user32" Alias "IsWindowVisible" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Const WM_GETTEXT As Integer = &HD
Private Const WM_GETTEXTLENGTH As Integer = &HE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' find msgbox
Dim iHwnd As IntPtr = FindWindow("#32770", "TheRecord Player") ' replace vbNullString with msgbox Titlebar text for best results!
If iHwnd <> IntPtr.Zero Then
' Enum: get top level child windows
GetChildWindows(iHwnd)
' search for visible static class that has text
For i As Integer = 0 To children.Count - 1
If children(i).ClassName = "Static" Then
' test if visible (windows msgboxes can have multiple hidden static classes.)
If IsWindowVisible(children(i).hWnd) = True Then
Dim txt As String = GetText(children(i).hWnd)
' test text length
If txt.Length > 1 Then
MessageBox.Show(txt)
Exit For
End If
End If
End If
Next
Else
MsgBox("window not found")
End If
End Sub
Private Function GetText(ByVal WindowHandle As IntPtr) As String
Dim TextLen As Integer = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0, 0) + 1
Dim Buffer As String = New String(" "c, TextLen)
SendMessageByString(WindowHandle, WM_GETTEXT, TextLen, Buffer)
Return Buffer.Trim
End Function
End Class
And I have a module1:
Imports System.Runtime.InteropServices
Module Module1
Public Structure ChldInfo
Public hWnd As IntPtr
Public ClassName As String
Public Sub New(ByVal hwnd As IntPtr, ByVal clsname As String)
Me.hWnd = hwnd
Me.ClassName = clsname
End Sub
End Structure
Public children As List(Of ChldInfo)
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
End Sub
Private Delegate Function EnumCallBackDelegate(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Integer
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As IntPtr) As IntPtr
Private Function EnumProc(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Int32
If hwnd <> IntPtr.Zero Then
children.Add(New ChldInfo(hwnd, Get_ClassName(hwnd)))
End If
Return 1
End Function
Private Function Get_ClassName(ByVal hWnd As IntPtr) As String
Dim sbClassName As New System.Text.StringBuilder("", 256)
Call GetClassName(hWnd, sbClassName, 256)
Return sbClassName.ToString
End Function
Public Sub GetChildWindows(ByVal hwnd As IntPtr)
children = New List(Of ChldInfo)
EnumChildWindows(hwnd, AddressOf EnumProc, Nothing)
End Sub
End Module
so right now as I'm using the program TheRecord Player that child window is showing a value of 1:44:30 PM. I want to grab that text from it. Hopefully I've explained myself well enough. I'[m not sure how extensive someone is willing to help with this, but the program is available from fortherecord.com (The free player)
Thanks in advance
-
Jan 20th, 2014, 12:07 PM
#2
Re: Retrieving information from another application
Hopefully I've explained myself well enough.
Well we got there in the end after a fairly ropy start! Yeah, I don't mind taking a look at this but it may be a day or two.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 21st, 2014, 02:52 PM
#3
Re: Retrieving information from another application
I've had a quick look at this but I think you must be using an older version than the one currently available as I am unable to get even as far as you have. It certainly doesn't appear to be a standard textbox so there would be no way to obtain its contents. Sorry.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 23rd, 2014, 04:06 PM
#4
Thread Starter
Member
Re: Retrieving information from another application
Well, I do appreciate you taking the time to look at it. I remembered a program called cheat engine or game hack where they look at the memory's address for changes in values in which you can narrow it down to the value you're looking for. Seems like that'd be quite the drawn out process to even think about using a method such as that to obtain these values. Ah well.. time to write to the software company and tell them to implement a global short cut key that grabs that time from their program
Thanks again for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|