Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click on a button in another application from my C# application?

Tags:

c#

.net

api

I want to click on a button in another application from my C# application ,
and I don't have the source code for the application that contains the button

let us say as an example ...can I use windows calculator from my application by clicking its buttons Programmatically
I am using c# and .NET
I think I must use windows api to do this
does anybody have any idea????

like image 321
Ahmad Houri Avatar asked Feb 04 '11 15:02

Ahmad Houri


People also ask

How to click a button in another application programmatically in c#?

We can "manually" execute Calculator and type "2+2=" into it. Then when we execute our sample application it can just click the "=" button and we can see the result. Look for "Contol ID" near the botom of the first (General) tab. It will probably have the value "00000079".

How do I add a button to Windows C form?

Creating a C# Button To create a Button control, you simply drag and drop a Button control from Toolbox to Form in Visual Studio. After you drag and drop a Button to a Form, the Button looks like Figure 1. Once a Button is on the Form, you can move it around and resize it.


1 Answers

Yes, it's not too complicated. You can use FindWindowEx to get the window handle, then iterate through the windows elements and use sendmessage or postmessage to send the WM_Click message.

Here's a codeproject project that does exactly what you want.

Code project

like image 57
Ian Avatar answered Sep 19 '22 10:09

Ian