473,542 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clicking button in external app

Hello everyone, my program is supposed to click a button on another
application when I click a button on my application. If I use a spy
program to get its identity, how can I do this? I know I should use
winapi and the interop services, but I cant quite set the code up to
work. Ive managed to get the window focus so far with winapi, so all I
need to do is execute a specific button. any know how to do this when I
click the button on my program?

Feb 3 '06 #1
7 7908
Hello, blah!

b> Hello everyone, my program is supposed to click a button on another
b> application when I click a button on my application. If I use a spy
b> program to get its identity, how can I do this? I know I should use
b> winapi and the interop services, but I cant quite set the code up to
b> work. Ive managed to get the window focus so far with winapi, so all I
b> need to do is execute a specific button. any know how to do this when I
b> click the button on my program?

You have to get the window handle of the button, and then call SendMessage on this handle with
BM_CLICK message.

You can use Spy++ took to get window name of the button.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 3 '06 #2
blah,

What you want to do is to define the SendMessage API function and send
the BM_CLICK message to the button (assuming you have the handle to it).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"blah" <so********@yah oo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hello everyone, my program is supposed to click a button on another
application when I click a button on my application. If I use a spy
program to get its identity, how can I do this? I know I should use
winapi and the interop services, but I cant quite set the code up to
work. Ive managed to get the window focus so far with winapi, so all I
need to do is execute a specific button. any know how to do this when I
click the button on my program?

Feb 3 '06 #3
Thank you for the replies, Im not at my computer right now but would
the code by any chance look something like this (upon button click):
{
HWND w = FindWindow("Win dow Class", NULL);
{
SendMessage(w, WM_LBUTTONDOWN, 0, 0);
}
}
unfortunately I cant try it right now, but since it looks so simple Im
guessing its wrong anyway?

Feb 3 '06 #4
blah,

Yes, it will look like that, but you have to convert it to .NET.

Also, passing WM_LBUTTONDOWN is INCORRECT. You need to pass BM_CLICK.
This will correctly simulate a click on the button (the button down event,
the click event, the button up event, etc, etc).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"blah" <so********@yah oo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Thank you for the replies, Im not at my computer right now but would
the code by any chance look something like this (upon button click):
{
HWND w = FindWindow("Win dow Class", NULL);
{
SendMessage(w, WM_LBUTTONDOWN, 0, 0);
}
}
unfortunately I cant try it right now, but since it looks so simple Im
guessing its wrong anyway?

Feb 3 '06 #5
Oh yes, BM_CLICK!, I was thinking too much into it. I will give it a
try when I can. Thanks for the assistance!

Feb 3 '06 #6
How does find window work if the button is in a differnt application? What
if the app is currntly showing mulitple buttons? How do you know you got the
right one?

Also SendMessage, I'm guessing you have to import it using
System.Runtime. InteropServices ?

I ask as I have a whole set of routines that I DLL Imported a bunch of APIs
for doing this, EnumWindows, EnumChildern, Send/Post Message, and defined a
bunch of constants for the messages.

Thanks
Wayne Sepega

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:e4******** ******@TK2MSFTN GP10.phx.gbl...
blah,

Yes, it will look like that, but you have to convert it to .NET.

Also, passing WM_LBUTTONDOWN is INCORRECT. You need to pass BM_CLICK.
This will correctly simulate a click on the button (the button down event,
the click event, the button up event, etc, etc).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"blah" <so********@yah oo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Thank you for the replies, Im not at my computer right now but would
the code by any chance look something like this (upon button click):
{
HWND w = FindWindow("Win dow Class", NULL);
{
SendMessage(w, WM_LBUTTONDOWN, 0, 0);
}
}
unfortunately I cant try it right now, but since it looks so simple Im
guessing its wrong anyway?


Feb 3 '06 #7
Wayne,
How does find window work if the button is in a differnt application? What
if the app is currntly showing mulitple buttons? How do you know you got
the right one?
That's up to you to figure out. You can traverse the handle tree and
try to filter it out yourself, or use FindWindow. However, it's not easy to
do, and you have to be very sure of which window you are trying to
communicate to (which is a reason why as a cross process mechanism, this
isn't the best, but sometimes, it is the only way).

Also SendMessage, I'm guessing you have to import it using
System.Runtime. InteropServices ?
Yes, the attributes defined in there will help you define SendMessage
for use in C# code.
I ask as I have a whole set of routines that I DLL Imported a bunch of
APIs for doing this, EnumWindows, EnumChildern, Send/Post Message, and
defined a bunch of constants for the messages.
You might want to check http://www.pinvoke.net, as it will have a good
number of definitions (constants, functions and structs) there as well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

Thanks
Wayne Sepega

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:e4******** ******@TK2MSFTN GP10.phx.gbl...
blah,

Yes, it will look like that, but you have to convert it to .NET.

Also, passing WM_LBUTTONDOWN is INCORRECT. You need to pass BM_CLICK.
This will correctly simulate a click on the button (the button down
event, the click event, the button up event, etc, etc).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"blah" <so********@yah oo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Thank you for the replies, Im not at my computer right now but would
the code by any chance look something like this (upon button click):
{
HWND w = FindWindow("Win dow Class", NULL);
{
SendMessage(w, WM_LBUTTONDOWN, 0, 0);
}
}
unfortunately I cant try it right now, but since it looks so simple Im
guessing its wrong anyway?



Feb 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2237
by: Botao | last post by:
Hi, Every Guru, I'd like to put a button on a page. When clicking the button, the table below it gets selected so the user can do Ctrl C to copy the entire table without using the mouse to select the table which can be big. How do I do it using javascript? I tried: <INPUT TYPE=Button NAME='Select' SIZE='10' VALUE='SelctTable'...
4
5961
by: Pieter Linden | last post by:
In Access 2000, I would have sworn I could see the controltiptext of a button without clicking on it. Can this still be done in AccessXP? If so, does someone have a code snippet showing how to do it? I can only get it to work by clicking the button... Thanks, Pieter
10
2532
by: Jim Bayers | last post by:
We need to stop students from clicking on the form button more than once. We have a form that students fill out with their credit card information. They click, the form sends the data in xml to Bank of America, theres a short wait, BofA sends back some xml, and on to the next page. Sometimes, though, BofA is slow and the students get...
9
2755
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub ...
7
7847
by: support | last post by:
Hi, I am trying to change the text of a Command button using the Windows API Function SetWindowText, which I have declared as follows: <DllImport("User32")_ Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal lpString As String) As Boolean End Function
5
3948
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any one help me in this regard.? The question is:...
6
3960
by: mikes8arms | last post by:
Version: Flash MX (A.S. 2.0) Hello. I haven't posted since signing on a few weeks ago. I've searched your site seeking an answer or answers to the concept of creating a "close button" for my external swf's. I've also searched engines; Ask.com, Yahoo.com, Lycos.com, etc.. I've tried the following methods of code as solutions, with no...
1
2631
by: Kirthikaiitm | last post by:
Hi, I have a image button (APPLY) On clicking apply button how to move the content from textbox to another textarea. I wrote the code in JScript. But once i click APPLY button the form is getting refreshed and the content in test area get vanished. How to retain the value on text area or how to avoid refreshing form on clicking image...
2
4404
by: iamdennis | last post by:
Hi all. I stuck here and need some help. I have created a combo box which contains a list of links to external PDF files. I also created a OPEN command button next to the combo box. I want to be able to select a file from the list and use the command button to open this external PDF file. I already know how to use just a command button...
0
7392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5246
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4880
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
943
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.