473,511 Members | 16,846 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 7904
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.com

"blah" <so********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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("Window 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.com

"blah" <so********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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("Window 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.com> wrote in
message news:e4**************@TK2MSFTNGP10.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.com

"blah" <so********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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("Window 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.com

Thanks
Wayne Sepega

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:e4**************@TK2MSFTNGP10.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.com

"blah" <so********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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("Window 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
2236
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...
4
5957
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...
10
2531
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...
9
2752
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...
7
7843
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...
5
3946
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...
6
3958
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...
1
2629
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...
2
4396
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...
0
7242
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
7355
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,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
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
4737
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
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.