Presionar boton de un programa externo. ( VB. Net )

(1/1)

70N1:
Necesito ejecutar un programa externo algo como process.start pero luego quiero presionar un boton que contiene el programa.

Necesito algo de informacion al respecto.
Cualquier comentario es bienvenido.

elmaro:
Para hacer eso tenes que saber el handle del botón que quieres presionar. Y enviarle con SendMessage "un click"

Acá tienes el código del SendMessage:
Código
   <System.Runtime.InteropServices.DllImport("user32.DLL")> _
   Public Function SendMessage( _
           ByVal hWnd As System.IntPtr, ByVal wMsg As Integer, _
           ByVal wParam As Integer, ByVal lParam As Integer _
           ) As Integer
   End Function
 
   <System.Runtime.InteropServices.DllImport("user32.DLL")> _
Public Function SendMessage( _
       ByVal hWnd As System.IntPtr, ByVal wMsg As Integer, _
       ByVal wParam As Integer, ByVal lParam As String _
       ) As Integer
   End Function

Para buscar el handle del boton puedes instalarte WinID (asi sabes como buscarlo desde la aplicacion)

Seguramente te sirvan todas estas funciones:
Código
<System.Runtime.InteropServices.DllImport("user32.dll", _
   EntryPoint:="FindWindow")> _
   Public Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
   End Function
 
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Public Function EnumChildWindows(ByVal hWndParent As System.IntPtr, ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Integer) As Boolean
   End Function
 
   Public Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
       Dim ChildrenList As New List(Of IntPtr)
       Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
       Try
           EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
       Finally
           If ListHandle.IsAllocated Then ListHandle.Free()
       End Try
       Return ChildrenList.ToArray
   End Function
 
   Private Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
       Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target
       If ChildrenList Is Nothing Then Throw New Exception("GCHandle Target could not be cast as List(Of IntPtr)")
       ChildrenList.Add(Handle)
       Return True
   End Function
 
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Public Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
       ' Leave function empty    
   End Sub

Lo que no se es cual es la constante a enviar. Quedaría buscar por ahí

Saludos

70N1:
Muchas gracias. Yo me imaginava que era algo de sendmessage o sendkey, aunque con sendmessage es mejor ya que no keda tan chapuza. Voy a trabajar con los codigos que me as proporcionado. muchas gracias.

elmaro:
Viendo por ahi creo que esta es la constante


Código
Private Const BM_CLICK = &HF5

m[a]rkus:
Hola, mira tengo un problema que necesito saber el hwnd de una sub-ventana, o sea ya tome la hwnd de la principal con Findwindows, y ahora con FindwindowsEX en teoria deberia tomar la que quiero, pero al parecer ahí otra ventana mas por medio, entonces necesito listar las ventanas hijas, ahí una API pero no la entiendo, con Spy++ ya eh mirado y no veo ni siquiera el que yo quiero a menos que lo haga con la "mirilla" y con el WINID que dijo sebasneo123 no salen las ventanas hijas, alguna idea ? gracias

Navegación

[0] Índice de Mensajes