下面是一個使用FindWindowEx函數的示例,該函數是在Visual Basic中找到指定窗口的子窗口的一種方法。
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Sub FindChildWindow()
Dim parentHwnd As Long
Dim childHwnd As Long
Dim className As String
Dim windowName As String
parentHwnd = FindWindow(vbNullString, "Parent Window Title") ' 根據父窗口標題找到父窗口的句柄
If parentHwnd <> 0 Then
className = "ChildWindowClass" ' 子窗口的類名
windowName = "Child Window Title" ' 子窗口的標題
childHwnd = FindWindowEx(parentHwnd, 0, className, windowName) ' 根據父窗口的句柄、子窗口的類名和標題找到子窗口的句柄
If childHwnd <> 0 Then
MsgBox "找到子窗口!"
Else
MsgBox "未找到子窗口。"
End If
Else
MsgBox "未找到父窗口。"
End If
End Sub
在上面的示例中,首先使用FindWindow函數根據父窗口的標題找到父窗口的句柄。然后使用FindWindowEx函數根據父窗口的句柄、子窗口的類名和標題找到子窗口的句柄。如果找到了子窗口,則顯示一個消息框提示找到子窗口;否則,顯示一個消息框提示未找到子窗口。