Pregunta: | 28453 - COMO PUEDO BUSCAR TODOS LAS VENTANAS(HANDLES) CON APIS? |
Autor: | Raúl Muñoz |
Como puedo hacer un bucle para usar todos los handles de todas las ventanas que haya en ese momento? |
Respuesta: | Enrique Gondra Churruca |
Puedes hacerlo utilizadon la API de Windows EnumWindows. Aquí va un ejemplo:
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim slength As Long, buffer As String ' title bar text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated.... slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text If slength > 1 Then ' if return value refers to non-empty string buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd, buffer, slength) ' get title bar text Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window End If EnumWindowsProc = 1 ' return value of 1 means continue enumeration End Function Private Sub Command1_Click() Dim retval As Long ' return value retval = EnumWindows(AddressOf EnumWindowsProc, 0) End Sub Espero que te sirva, Enrique |