Scusa ma l'API ChildWindow non esiste!
Era una funzione che avevo fatto io!
Ecco un esempio che riempie un array di tipo finestra con tutte le finestre aperte:
codice:
'Serve per getwindowrect
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type Finestra
Handle As Long
Titolo As String
Visibile As Boolean
Stato As FormWindowStateConstants
PosY As Long
PosX As Long
Altezza As Long
Larghezza As Long
End Type
'Dichiarazioni API
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
'Costanti API
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Sub RiempiVettore(ByRef arr() As Finestra)
Dim h As Long, tot As Integer
Dim Buf As String * 255
Dim LunghezzaTitolo As Long
Dim Pos As RECT
tot = 0
h = GetWindow(GetDesktopWindow, GW_CHILD)
Do While h <> 0
tot = tot + 1
ReDim Preserve arr(tot - 1) As Finestra
'Imposta l'handle
arr(tot - 1).Handle = h
'Calcola il titolo con GetWindowText()
Buf = String(255, " ")
LunghezzaTitolo = GetWindowText(h, Buf, 255)
arr(tot - 1).Titolo = Left(Buf, LunghezzaTitolo)
'Calcola altezza, larghezza e posizione
Call GetWindowRect(h, Pos)
arr(tot - 1).PosX = Pos.Left
arr(tot - 1).PosY = Pos.Top
arr(tot - 1).Altezza = Pos.Bottom - Pos.Top
arr(tot - 1).Altezza = Pos.Right - Pos.Left
'Calcola se è visibile
arr(tot - 1).Visibile = IsWindowVisible(h)
'Calcola lo stato
If IsIconic(h) Then
'Ridotto ad icona
arr(tot - 1).Stato = vbMinimized
ElseIf IsZoomed(h) Then
'Ingrandito
arr(tot - 1).Stato = vbMaximized
Else
'Normale
arr(tot - 1).Stato = vbNormal
End If
'Prossima finestra
h = GetWindow(h, GW_HWNDNEXT)
Loop
End Sub
Private Sub Form_Load()
Dim arr() As Finestra
Call RiempiVettore(arr())
End Sub