我已經編寫了一個程序,用於在另一個程序中查找一個框並將焦點設置爲該框。一旦完成,它將發送密鑰並保存到此框中。FindWindow FindWindowEx
我正在使用Findwindow和FindwindowEx來定位框,但我有點問題。 如果你注意到窗口一直到第一個TPanel都一樣。之後有3Tpanel類。 3Tpanel類之後有多個TttgEdit類。
如何教我選擇的課程? 到目前爲止,這是我的代碼。
Delcare
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,他們改變每屏幕開和關的時間,所以我不能把它們作爲一個靜態的數字。任何幫助都是極好的。
對不起延遲。這是現貨。謝謝 – user1946138