Autor
|
Tema: Ayuda con funcion listar ventanas en Array (Leído 2,334 veces)
|
| SMT |
Desconectado
Mensajes: 4
|
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: ' 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: EnumWindows AddressOf mEnumWindows, 0& Sera que me pueden brinda una mano en que hago mal? Gracias y saludos.
|
|
|
En línea
|
|
|
|
Danyfirex
Desconectado
Mensajes: 493
My Dear Mizuho
|
IsWindowVisible? mira este ejemplo 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
saludos
|
|
|
En línea
|
|
|
|
| SMT |
Desconectado
Mensajes: 4
|
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
Mensajes: 624
|
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 BooleanReDim Preserve ListEnumWindow( Proc) mEnumWindows = True '(antes de End Function) FORM 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 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
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Función que devuelva un array (javascript)
Desarrollo Web
|
Fox_Neo
|
5
|
18,060
|
13 Diciembre 2010, 15:31 pm
por Fox_Neo
|
|
|
Pasar un array por una función
PHP
|
dimitrix
|
8
|
4,193
|
19 Junio 2011, 22:47 pm
por cassiani
|
|
|
ayuda con listar productos
PHP
|
tecasoft
|
2
|
2,008
|
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
|
8 Febrero 2018, 00:27 am
por Eleкtro
|
|
|
[python] Ayuda a listar busquedas
Scripting
|
Ankrex
|
4
|
2,591
|
16 Noviembre 2019, 23:44 pm
por Ankrex
|
|