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
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