您的代码存在一些问题。
您要查找的编辑器窗口是 MDI 子窗口,因此您需要先获取HWND
其父MDIClient
窗口的,您没有这样做。
在您的最终FindWindowEx()
通话中,您将在参数中传递编辑器的文本lpszClass
而不是lpszWindow
参数。
您不能总是将子窗口传递给SetForegroundWindow()
. 既然你知道编辑器是 MDI 的孩子,你应该指示 MDI 使编辑器成为焦点,如果这是你想要做的。
试试这个:
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