I wrote a program that should find a field in another program and set focus on it. Once this is done, he will send the keys and save them in this field.
I use Findwindow and FindwindowEx to find the field, but I have a problem.
if you notice that the windows are the same up to the first TPanel. Now after that there are 3Tpanel classes. After the 3Tpanel classes, there are several TttgEdit classes.
How can I teach the program which classes I want to choose? Here is my code so far.
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
A source
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)
The numbers on the left are hWnd. They change every time the screen is closed and open, so I cannot use them as a static number. Any help would be awesome.