- Option Explicit 
-   
- 'Esta función Api devuelve un valor  Boolean indicando si la ventana es una ventana visible 
- Private Declare Function IsWindowVisible _ 
-     Lib "user32" ( _ 
-         ByVal hwnd As Long) As Long 
-   
- 'Esta función retorna el número de caracteres del caption de la ventana 
- Private Declare Function GetWindowTextLength _ 
-     Lib "user32" _ 
-     Alias "GetWindowTextLengthA" ( _ 
-         ByVal hwnd As Long) As Long 
-   
- 'Esta devuelve el texto. Se le pasa el hwnd de la ventana, un buffer donde se 
- 'almacenará el texto devuelto, y el Lenght de la cadena en el último parámetro 
- 'que obtuvimos con el Api GetWindowTextLength 
- Private Declare Function GetWindowText _ 
-     Lib "user32" _ 
-     Alias "GetWindowTextA" ( _ 
-         ByVal hwnd As Long, _ 
-         ByVal lpString As String, _ 
-         ByVal cch As Long) As Long 
-   
- 'Esta es la función Api que busca las ventanas y retorna su handle o Hwnd 
- Private Declare Function GetWindow _ 
-     Lib "user32" ( _ 
-         ByVal hwnd As Long, _ 
-         ByVal wFlag As Long) As Long 
-   
-       Private Declare Function SetWindowText Lib "user32.dll" Alias _ 
- "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long 
-   
- 'Constantes para buscar las ventanas mediante el Api GetWindow 
- Private Const GW_HWNDFIRST = 0& 
- Private Const GW_HWNDNEXT = 2& 
- Private Const GW_CHILD = 5& 
-   
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
-   
- 'Procedimiento que lista las ventanas visibles de Windows 
- Private Sub Listar() 
-   
- Dim buf As Long, handle As Long, titulo As String, lenT As Long, ret As Long 
- Dim retval As Long 
-     List1.Clear 
-     'Obtenemos el Hwnd de la primera ventana, usando la constante GW_HWNDFIRST 
-     handle = GetWindow(hwnd, GW_HWNDFIRST) 
-   
-     'Este bucle va a recorrer todas las ventanas. 
-     'cuando GetWindow devielva un 0, es por que no hay mas 
-     Do While handle <> 0 
-         'Tenemos que comprobar que la ventana es una de tipo visible 
-         If IsWindowVisible(handle) Then 
-             'Obtenemos el número de caracteres de la ventana 
-             lenT = GetWindowTextLength(handle) 
-             'si es el número anterior es mayor a 0 
-             If lenT > 0 Then 
-                 'Creamos un buffer. Este buffer tendrá el tamaño con la variable LenT 
-                 titulo = String$(lenT, 0) 
-                 'Ahora recuperamos el texto de la ventana en el buffer que le enviamos 
-                 'y también debemos pasarle el Hwnd de dicha ventana 
-                 ret = GetWindowText(handle, titulo, lenT + 1) 
-                 titulo$ = Left$(titulo, ret) 
-   
-                 'si el titulo de la ventana es igual a x titulo cambias y pones lo que sea. 
-                 If titulo = "titulo de ares" Then 
-                 ' return value 
-   
-                 retval = SetWindowText(handle, "Hola Mundo") 
-                 End If 
-                 'La agregamos al ListBox 
-                 List1.AddItem titulo$ 
-             End If 
-         End If 
-         'Buscamos con GetWindow la próxima ventana usando la constante GW_HWNDNEXT 
-         handle = GetWindow(handle, GW_HWNDNEXT) 
-     Loop 
- End Sub 
-   
- Private Sub Command1_Click() 
-     'Llamamos a la función Listar 
-     Call Listar 
- End Sub