473,503 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Click Button In Another Application

2 New Member
Hello All ..
I'm Trying to Click a Button In Another Application With Process Name "CenterBot"
I have got ListView1 , Button1 , Button2
Here's my code

Expand|Select|Wrap|Line Numbers
  1. Imports System.Runtime.InteropServices
  2. Public Class Form1
  3.  
  4.  Private Const BM_CLICK = &HF5
  5.     Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As IntPtr, ByVal wMsg As UInteger, ByVal wParam As UInteger, ByVal lParam As UInteger) As UInteger
  6.     Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Integer, ByVal lpWindowName As String) As Int32
  7.  
  8.     Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
  9.     ByVal hWndParent As IntPtr, _
  10.     ByVal hWndChildAfter As IntPtr, _
  11.     <MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszClass As String, _
  12.     <MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszWindow As String _
  13.     ) As IntPtr
  14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.         ListView1.Items.Clear()
  16.         For Each x As Process In Process.GetProcessesByName("CenterBot")
  17.  
  18.                 Dim A = ListView1.Items.Add(x.ProcessName)
  19.                 A.SubItems.Add(x.MainWindowTitle)
  20.                 A.SubItems.Add(x.Id)
  21.             End If
  22.         Next
  23.     End Sub
  24.  
  25.  
  26. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  27.         On Error Resume Next
  28.         If ListView1.SelectedItems.Count = 0 Then
  29.             MessageBox.Show("Choose Your Process For the list", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
  30.         Else
  31.             Dim HWND As Integer = FindWindow(0, ListView1.SelectedItems.Item(0).SubItems(1).Text)
  32.             If HWND = 0 Then
  33.                 MessageBox.Show("Choose Your Process For the list", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
  34.                 Exit Sub
  35.             Else
  36.                 Dim ChildWndHandle As IntPtr
  37.  
  38.  
  39. ChildWndHandle = FindWindowEx(HWND, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.2bf8098_r13_ad1", "Button Text")
  40.                 MsgBox(ChildWndHandle)
  41.                 SendMessage(ChildWndHandle, BM_CLICK, 1, 0)
  42.   End If
  43.         End If
  44.     End Sub
  45. End Class
  46.  
This Code is working well if the button on the form
but the button in a groupbox
also the groupbox in a TabControl !!

Hope i get helped here ;)
Aug 7 '14 #1
0 1221

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1598
by: [Yosi] | last post by:
I search solution for a little bit strange problem , I working on an application which includes a button. Click on this button will create number of threads each one execute deferent executable...
5
6801
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
6
1129
by: Agnes | last post by:
In myForm, i need to let user just click one button and then Start another application . Does anyone know how to do ?? Thanks a lot.
4
1529
by: Linda | last post by:
If I wanted a VB application to find the edit box of another, external application, and enter text into this edit box, how would I go about doing this? How do I get the handle for a specific...
5
2075
by: DBC User | last post by:
Hello, I would like to know how can I start another application that is installed in the PC from another running application? Both the applications are installed through click once so I can not...
1
1995
by: Terry Olsen | last post by:
Is there any way for my app to capture a keypress or a button click from another app? I need my app to be able to catch the click before the other app and process the click or keypress instead. ...
4
1252
by: rayne | last post by:
hi pls help me on how to open another application by clicking a button. What I want to do is when I click a button, another application will open. thanks
3
1942
by: eddie69 | last post by:
Hi, Newbie question here: I am creating an application in VB Studio 2005 which reads the status of an USB PIR Motion sensor. So far, I have managed to get the application to read the motion...
12
65279
by: Thammarat charoenchai. | last post by:
Hi, I'm try to learn vb.net. in delphi have .click method for click button by coding. Can I do that with vb.net Thank you very much.
6
5639
by: Paulers | last post by:
Hello, I am trying to manipulate a console based application from another application for example I need to launch the console application, provide it input and take the output from the console...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.