elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Ayuda con funcion listar ventanas en Array
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con funcion listar ventanas en Array  (Leído 2,334 veces)
| SMT |

Desconectado Desconectado

Mensajes: 4


Ver Perfil
Ayuda con funcion listar ventanas en Array
« en: 6 Agosto 2013, 00:48 am »

Buenas tengo un problema con una función (Realmente llevo mucho tiempo sin programar y ando haciendo pequeñas "funciones" para generalizarme de nuevo con VB6) lo que mi funcion hace es listar las ventanas, ver si estan visible si es correcto obtiene el caption y luego la almacena en un array.

El problema es que la función no me sirve, no puedo obtener los valores del array para listarlo, no se si es que no manejo bien el array... Busque ayuda (bastante) en Internet y la mayoría de ejemplos lista todo los caption de una vez en algún control pero no consigo un ejemplo en Array.
Aqui anexo el codigo esto va en un Modulo .Bas:

Código:
' Lista las ventanas
Public Declare Function EnumWindows Lib "user32" ( _
                 ByVal wndenmprc As Long, _
                 ByVal lParam As Long) As Long
       
' Obtener el título de la ventana
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

'LISTA VENTANAS
Public ListEnumWindow() As String
Public Proc As Integer

Public Function mEnumWindows(ByVal wHwnd As Long, ByVal lParam As Long) As Long
Dim wLen As Long
Dim GetText As Long
Dim wText As String

If IsWindowVisible(wHwnd) <> 0 Then
    wLen = GetWindowTextLength(wHwnd)
    If wLen > 0 Then
        wText = Space$(wLen + 1)
        GetWindowText wHwnd, wText, Len(wText)
            Proc = Proc + 1
            ReDim Preserve ListEnumWindow(1 To Proc)
            ListEnumWindow(Proc) = wText
    Else
        'COMANDO ELSE
    End If
Else
    'COMANDO ELSE
End If
End Function

Y para ejecutarlo lo hago de la siguiente manera:

Código:
EnumWindows AddressOf mEnumWindows, 0&

Sera que me pueden brinda una mano en que hago mal?

Gracias y saludos.


En línea

Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: Ayuda con funcion listar ventanas en Array
« Respuesta #1 en: 6 Agosto 2013, 13:56 pm »

IsWindowVisible?  :-(


mira este ejemplo

Código
  1. Option Explicit
  2.  
  3. 'Esta función Api devuelve un valor  Boolean indicando si la ventana es una ventana visible
  4. Private Declare Function IsWindowVisible _
  5.    Lib "user32" ( _
  6.        ByVal hwnd As Long) As Long
  7.  
  8. 'Esta función retorna el número de caracteres del caption de la ventana
  9. Private Declare Function GetWindowTextLength _
  10.    Lib "user32" _
  11.    Alias "GetWindowTextLengthA" ( _
  12.        ByVal hwnd As Long) As Long
  13.  
  14. 'Esta devuelve el texto. Se le pasa el hwnd de la ventana, un buffer donde se
  15. 'almacenará el texto devuelto, y el Lenght de la cadena en el último parámetro
  16. 'que obtuvimos con el Api GetWindowTextLength
  17. Private Declare Function GetWindowText _
  18.    Lib "user32" _
  19.    Alias "GetWindowTextA" ( _
  20.        ByVal hwnd As Long, _
  21.        ByVal lpString As String, _
  22.        ByVal cch As Long) As Long
  23.  
  24. 'Esta es la función Api que busca las ventanas y retorna su handle o Hwnd
  25. Private Declare Function GetWindow _
  26.    Lib "user32" ( _
  27.        ByVal hwnd As Long, _
  28.        ByVal wFlag As Long) As Long
  29.  
  30.      Private Declare Function SetWindowText Lib "user32.dll" Alias _
  31. "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
  32.  
  33. 'Constantes para buscar las ventanas mediante el Api GetWindow
  34. Private Const GW_HWNDFIRST = 0&
  35. Private Const GW_HWNDNEXT = 2&
  36. Private Const GW_CHILD = 5&
  37.  
  38. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  39.  
  40. 'Procedimiento que lista las ventanas visibles de Windows
  41. Private Sub Listar()
  42.  
  43. Dim buf As Long, handle As Long, titulo As String, lenT As Long, ret As Long
  44. Dim retval As Long
  45.    List1.Clear
  46.    'Obtenemos el Hwnd de la primera ventana, usando la constante GW_HWNDFIRST
  47.    handle = GetWindow(hwnd, GW_HWNDFIRST)
  48.  
  49.    'Este bucle va a recorrer todas las ventanas.
  50.    'cuando GetWindow devielva un 0, es por que no hay mas
  51.    Do While handle <> 0
  52.        'Tenemos que comprobar que la ventana es una de tipo visible
  53.        If IsWindowVisible(handle) Then
  54.            'Obtenemos el número de caracteres de la ventana
  55.            lenT = GetWindowTextLength(handle)
  56.            'si es el número anterior es mayor a 0
  57.            If lenT > 0 Then
  58.                'Creamos un buffer. Este buffer tendrá el tamaño con la variable LenT
  59.                titulo = String$(lenT, 0)
  60.                'Ahora recuperamos el texto de la ventana en el buffer que le enviamos
  61.                'y también debemos pasarle el Hwnd de dicha ventana
  62.                ret = GetWindowText(handle, titulo, lenT + 1)
  63.                titulo$ = Left$(titulo, ret)
  64.  
  65.                'si el titulo de la ventana es igual a x titulo cambias y pones lo que sea.
  66.                If titulo = "titulo de ares" Then
  67.                ' return value
  68.  
  69.                retval = SetWindowText(handle, "Hola Mundo")
  70.                End If
  71.                'La agregamos al ListBox
  72.                List1.AddItem titulo$
  73.            End If
  74.        End If
  75.        'Buscamos con GetWindow la próxima ventana usando la constante GW_HWNDNEXT
  76.        handle = GetWindow(handle, GW_HWNDNEXT)
  77.    Loop
  78. End Sub
  79.  
  80. Private Sub Command1_Click()
  81.    'Llamamos a la función Listar
  82.    Call Listar
  83. End Sub

saludos


En línea

| SMT |

Desconectado Desconectado

Mensajes: 4


Ver Perfil
Re: Ayuda con funcion listar ventanas en Array
« Respuesta #2 en: 11 Agosto 2013, 09:08 am »

Hola DanyFirex, muchas gracias por tu respuesta ya logre solucionar parte del problema que tenia (Volvi a hacer el codigo desde 0) lo unico que no e logrado y no entiendo (o recuerdo) porque.. Es que quiero que todos los nombres se me almacenen en un Array en un modulo y que desde el Form pueda acceder al array, pero no puedo hacer eso...
Por casualidad sabes debido a que no puedo obtener los datos desde el array o sera que los agrego mal? Uso el Redim Preserver
En línea

Dessa


Desconectado Desconectado

Mensajes: 624



Ver Perfil
Re: Ayuda con funcion listar ventanas en Array
« Respuesta #3 en: 11 Agosto 2013, 16:25 pm »


debido a que no puedo obtener los datos desde el array o sera que los agrego mal? Uso el Redim Preserver

Private Function mEnumWindows(ByVal wHwnd As Long, ByVal lParam As Long) As Boolean

ReDim Preserve ListEnumWindow(Proc)

mEnumWindows = True  '(antes de End Function)

FORM

Código:

Option Explicit

Private Sub Form_Load()
  AutoRedraw = True
End Sub

Private Sub Command1_Click()
 
  Cls
 
  Call MakeArray
 
  Dim x As Long
  For x = 1 To UBound(ListEnumWindow)
    Print ListEnumWindow(x)
  Next

End Sub




MODULO

Código:

Option Explicit

Private Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, ByVal lParam 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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long

Public ListEnumWindow() As String
Private Proc As Integer

Public Sub MakeArray()
  Proc = 0
  Erase ListEnumWindow
  Call EnumWindows(AddressOf mEnumWindows, 0&)
End Sub

Private Function mEnumWindows(ByVal wHwnd As Long, ByVal lParam As Long) As Boolean

Dim wLen    As Long
Dim wText   As String

If IsWindowVisible(wHwnd) Then
    wLen = GetWindowTextLength(wHwnd)
    If wLen > 0 Then
        wText = Space$(wLen + 1)
        GetWindowText wHwnd, wText, Len(wText)
        Proc = Proc + 1
        ReDim Preserve ListEnumWindow(Proc)
        ListEnumWindow(Proc) = Replace(wText, Chr(0), "")
    End If
End If

mEnumWindows = True

End Function



En línea

Adrian Desanti
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Función que devuelva un array (javascript)
Desarrollo Web
Fox_Neo 5 18,060 Último mensaje 13 Diciembre 2010, 15:31 pm
por Fox_Neo
Pasar un array por una función
PHP
dimitrix 8 4,193 Último mensaje 19 Junio 2011, 22:47 pm
por cassiani
ayuda con listar productos
PHP
tecasoft 2 2,008 Último mensaje 6 Diciembre 2014, 17:20 pm
por tecasoft
[Bash] Listar los archivos de una carpeta e introducirlo en un array
Scripting
Javidod 1 4,254 Último mensaje 8 Febrero 2018, 00:27 am
por Eleкtro
[python] Ayuda a listar busquedas
Scripting
Ankrex 4 2,591 Último mensaje 16 Noviembre 2019, 23:44 pm
por Ankrex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines