FindWindow FindWindowEx

依然范特西╮ 提交于 2019-12-02 04:04:16

It looks like you want the second TPanel under the TttgCenterPanel.

In order to do that, you can find the first TPanel (you already did this), and after that, find the TPanel that is a descendant of TttgCenterPanel, and comes after the first TPanel. You need to pass hwndChild5 into the hwndChildAfter ofFindWindowEx`.

' .... all the stuff you did before

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 hWndChild6Second As IntPtr = _
FindWindowEx(hWndChild5, hWndChild6, "TPanel", Nothing)
If hWndChild6Second.Equals(IntPtr.Zero) Then
    Return
End If

Dim hWndEdit As IntPtr = _
FindWindowEx(hWndChild6Second, IntPtr.Zero, "TttgDBEdit", Nothing)
If hWndEdit.Equals(IntPtr.Zero) Then
    Return
End If

SetForegroundWindow(hWndEdit)

From the MSDN documentation of FindWindowEx:

hwndChildAfter [in, optional]

Type: HWND

A handle to a child window. The search begins with the next child window in the Z order. The child window must be a direct child window of hwndParent, not just a descendant window.

If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.

This approach will work if you are trying to find the second TPanel. If they are in random order each time, this will fail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!