vb.netwin32-processfindwindowex

VB.NET - I can't manage this window - Win32 - FindWindowEx


I trying to select a window in system process but it returns nothing.

Here is the window I'm trying to get:

enter image description here

What's wrong with the code below?

Sub Find_Window

    Dim Profit As Integer = Win32.FindWindow(Nothing, "ProfitPro - 5.0.0.35 - Registrado"
    Dim Menu As Integer = Win32.FindWindowEx(Profit, Nothing, "Editor de Estratégias", Nothing)

    If (Not Menu = 0) Then
        Win32.SetForegroundWindow(Menu)
        SendKeys.Send("{TAB}")
    End If

End Sub 

Solution

  • There are a few problems with your code.

    Try this instead:

    Sub Find_Window
    
        Dim Profit As IntPtr = Win32.FindWindow("TProfitChartForm", "ProfitPro - 5.0.0.35 - Registrado")
        Dim MDI As IntPtr = Win32.FindWindowEx(Profit, IntPtr.Zero, "MDIClient", "")
        Dim Editor As IntPtr = Win32.FindWindowEx(MDI, IntPtr.Zero, "TLanguageEditorForm", "Editor de Estratégias")
    
        If Editor <> 0 Then
            Win32.SetForegroundWindow(Profit)
            Win32.SendMessage(MDI, WM_MDIACTIVATE, Editor, 0)
            ' TODO: add this
            ' Dim ChildTextFieldInsideOfEditor as IntPtr = Win32.FindWindowEx(Editor, ...)
            ' Dim ThisThreadId = Win32.GetCurrentThreadId()
            ' Dim EditorThreadId as Integer = Win32.GetWindowThreadProcessId(Editor, ref ProcID)
            ' Win32.AttachThreadInput(ThisThreadId, EditorThreadId, True);
            ' Win32.SetFocus(ChildTextFieldInsideOfEditor)
            ' Win32.AttachThreadInput(ThisThreadId, EditorThreadId, False);
            SendKeys.Send("{TAB}")
        End If
    
    End Sub