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

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Obtener texto de la ventana abierta
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Obtener texto de la ventana abierta  (Leído 3,046 veces)
Stereo

Desconectado Desconectado

Mensajes: 25


Ver Perfil
Obtener texto de la ventana abierta
« en: 22 Mayo 2012, 19:44 pm »

Buenas, llevo todo el dia intentando obtener el titulo de la ventana que tienes abierta pero no lo he conseguido, e aqui mi intento:

Código:
Public Class Form1
    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 Function findPartialTitle(ByVal partialTitle As String) As IntPtr
        For Each p As Process In Process.GetProcesses()
            If p.MainWindowTitle.IndexOf(partialTitle, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
                '
                'We found a match, so return the handle to the window
                '
                Return p.MainWindowHandle
            End If
        Next

        '
        'If no match, return NULL (or close enough)
        '
        Return IntPtr.Zero
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hwnd As Long = findPartialTitle("YouTube")
        Dim lngLen As Integer = 512
        Dim MyStr As String
        'Create a buffer
        MyStr = 255

        'Get the window's text
        GetWindowText(hwnd, MyStr, 254)
        MsgBox("La ventana abierta no es correcta, intentalo de nuevo: " &MyStr)
    End Sub
End Class

El error al depurar es en esta linea:

Código:
GetWindowText(hwnd, MyStr, 254)


En línea

The Swash

Desconectado Desconectado

Mensajes: 194


Programmer


Ver Perfil WWW
Re: Obtener texto de la ventana abierta
« Respuesta #1 en: 22 Mayo 2012, 20:33 pm »

GetForeGroundWindow()
Retrieves a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
Código:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx


En línea

Stereo

Desconectado Desconectado

Mensajes: 25


Ver Perfil
Re: Obtener texto de la ventana abierta
« Respuesta #2 en: 22 Mayo 2012, 20:56 pm »

Gracias pero el caso es que esa función no la reconoce, uso visual studio 2010
En línea

noele1995

Desconectado Desconectado

Mensajes: 137



Ver Perfil
Re: Obtener texto de la ventana abierta
« Respuesta #3 en: 22 Mayo 2012, 21:00 pm »

Si no me equivoco eso es .net y hay un subforo para ello.

Aqui va el codigo

Código
  1. Private Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hWnd As Long,ByVal lpString As String, ByVal cch As Long) As Long  
  2. Private Declare Function GetForegroundWindow Lib "User32" () As Long  
  3.  
  4. public function TextoVentanaActiva() as string
  5.  
  6. Dim hwnd_Ventana As Long  
  7. Dim Caption_Ventana As String  
  8. Dim length As Long  
  9.  
  10.    ' Captura el Hwnd de la ventana activa  
  11.    hwnd_Ventana = GetForegroundWindow()  
  12.  
  13.    'Crea un Buffer
  14.    Caption_Ventana = Space$(1024)  
  15.  
  16.    ' Retorna la cantidad de caracteres  
  17.    length = GetWindowText(hwnd_Ventana, Caption_Ventana, Len(Caption_Ventana))  
  18.  
  19.    ' Obtiene solo el caption sin los espacios nulos de la cadena  
  20.    TextoVentanaActiva = Left$(Caption_Ventana, length)  
  21. end function
  22.  
En línea

Stereo

Desconectado Desconectado

Mensajes: 25


Ver Perfil
Re: Obtener texto de la ventana abierta
« Respuesta #4 en: 22 Mayo 2012, 21:21 pm »

Me sigue tirando error al empezar el programa con debug en esta linea :S

Dice: Se detectó PInvokeStackImbalance

Código:
length = GetWindowText(hwnd_Ventana, Caption_Ventana, Len(Caption_Ventana))
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ForceFore: Obtener controlador de ventana
Programación Visual Basic
vbasicred 0 989 Último mensaje 11 Junio 2006, 21:07 pm
por vbasicred
si una ventana esta abierta devolver el hwnd « 1 2 »
Programación Visual Basic
rubeng 16 5,041 Último mensaje 15 Septiembre 2007, 00:38 am
por rubeng
Programa que trabaje sin ventana abierta
Programación C/C++
marianoc 3 2,830 Último mensaje 14 Diciembre 2010, 19:17 pm
por Garfield07
Como Obtener el Texto de una Ventana en Japones? :P
Programación Visual Basic
x64core 4 2,183 Último mensaje 9 Noviembre 2011, 19:43 pm
por x64core
Obtener el Nombre de la ventana
.NET (C#, VB.NET, ASP)
BrokerJoker 4 3,005 Último mensaje 30 Enero 2012, 00:41 am
por Keyen Night
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines