This is going to be hard. See if you can get all the handles and if they change position between starts of the software. It would be better if you create a new project for testing.Code:Imports System.Runtime.InteropServices Private Declare Auto Function FindWindowEx Lib "user32" _ (ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _ ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr Private Declare Auto Function EnumChildWindows Lib "user32" _ (ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, _ ByVal lParam As IntPtr) As Boolean Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, _ ByVal Parameter As IntPtr) As Boolean Public Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr() Dim ChildrenList As New List(Of IntPtr) Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList) Try EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle)) Finally If ListHandle.IsAllocated Then ListHandle.Free() End Try Return ChildrenList.ToArray End Function Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean Dim ChildrenList As List(Of IntPtr) = CType(GCHandle.FromIntPtr(Parameter).Target, Global.System.Collections.Generic.List(Of Global.System.IntPtr)) If ChildrenList Is Nothing Then Throw New Exception("GCHandle Target could not be cast as List(Of IntPtr)") ChildrenList.Add(Handle) Return True End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim MainHandle As IntPtr MainHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "COBRAmain", Nothing) Dim ChildHandles() As IntPtr = GetChildWindows(MainHandle) For i As Integer = 0 To ChildHandles.Length - 1 ListBox1.Items.Add(i & ": " & System.Convert.ToString(ChildHandles(i).ToInt32, 16)) Next End Sub




Reply With Quote