我编写了一个程序,该程序是在另一个程序中找到一个框并将焦点设置在它上面。完成此操作后,它将发送密钥并保存到此框。
我正在使用 Findwindow 和 FindwindowEx 来定位该框,但我遇到了一些问题。 如果您注意到窗口一直到第一个 TPanel 都是相同的。现在之后有 3Tpanel 类。在 3Tpanel 类之后有多个 TttgEdit 类。
我如何教授我想要选择的课程?到目前为止,这是我的代码。
德尔卡
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hwndParent As IntPtr, _
ByVal hwndChildAfter As IntPtr, _
ByVal lpszClass As String, _
ByVal lpszWindow As String _
) As IntPtr
资源
Dim hWnd As IntPtr = FindWindow("TRunprgForm", Nothing)
If hWnd.Equals(IntPtr.Zero) Then
Return
End If
cb1.Checked = True
'--------------------instert here
Dim hWndChild1 As IntPtr = _
FindWindowEx(hWnd, IntPtr.Zero, "TmisinvForm", Nothing)
If hWndChild1.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndChild2 As IntPtr = _
FindWindowEx(hWndChild1, IntPtr.Zero, "TScrollBox", Nothing)
If hWndChild2.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndChild3 As IntPtr = _
FindWindowEx(hWndChild2, IntPtr.Zero, "TPageControl", Nothing)
If hWndChild3.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndChild4 As IntPtr = _
FindWindowEx(hWndChild3, IntPtr.Zero, "TTabSheet", Nothing)
If hWndChild4.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndChild5 As IntPtr = _
FindWindowEx(hWndChild4, IntPtr.Zero, "TttgCenterPanel", Nothing)
If hWndChild5.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndChild6 As IntPtr = _
FindWindowEx(hWndChild5, IntPtr.Zero, "TPanel", Nothing)
If hWndChild6.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndEdit As IntPtr = _
FindWindowEx(hWndChild6, IntPtr.Zero, "TttgDBEdit", Nothing)
If hWndEdit.Equals(IntPtr.Zero) Then
Return
End If
SetForegroundWindow(hWndEdit)
左侧的数字,hWnd,每次关闭和打开屏幕时都会改变,所以我不能将它们用作静态数字。任何帮助都是极好的。