• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[C#] "Pressing" a Button

Joined
Mar 22, 2008
Messages
830
Reaction score
158
OK, here is my question/problem/doubt...

Lets say I have an app that has two buttons.
button01 = Start
button02 = Exit

Is it possible to program an application that calls the button01 or 02, without actually pressing the button(clicking)?
If it is, anyone mind showing me an example?

Regards,
Alan
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Yes, debug/disassemble, find the wndproc handling the click, find the function it calls on a click to that button ID (you can get the ID with something like the spy tool that comes with visual studio), and if you call that code yourself, it will behave as if the button was clicked unless more logic is implemented to test for a click (this is rare). You can also simulate the message yourself with .

There may be tools to get a list of wndprocs for a process's HWNDs (maybe Process Explorer? That spy tool may do it too). You can do this manually with by passing the HWND of the control.

You can use EnumWindows to enumerate windows and drill down into children to find child controls etc with EnumChildWindows. I'm not sure the code for C# for any of this but if the application is written in C#, you can probably just decompile the CIL.

And the wndprocs for a C# application will probably exist in .NET CLR code that invokes CIL code, in that case I'm not sure what you'd want to do. You can probably just simulate a mouseclick.
 
Last edited:
Experienced Elementalist
Joined
Apr 12, 2009
Messages
241
Reaction score
32
if you want a lame hack that's easier than all that, just make a quick app that clicks an area on the screen and teach it where both buttons are :p
 
Joined
Mar 22, 2008
Messages
830
Reaction score
158
if you want a lame hack that's easier than all that, just make a quick app that clicks an area on the screen and teach it where both buttons are :p
Do you think I am stupid?
I am making attempting to create a small application capable of opening and clicking on a launcher's buttons... The launcher is in Chinese and people are too lazy and stupid to follow the directions I gave them, so I decided to make a "loader"...
 
Experienced Elementalist
Joined
Apr 12, 2009
Messages
241
Reaction score
32
Hah. I've made tens of thousands of dollars with that solution that you think i'm calling you stupid for suggesting :p

I don't think you're stupid - was just suggesting a simple solution if it was a simple problem :)
 
Back
Top