Link to home
Start Free TrialLog in
Avatar of frangers99
frangers99

asked on

pressing buttons

Is there a simple piece of code that enables you to press buttons on external applications. I have looked around and found different solutions, but none seem to work. So any ideas?

I currently use findwindow to get the window handle. the findwindowex to get the button handle and i have tried
sendmessage(handle,WM_KEYDOWN,13,0) then key up but this doesn't work
Avatar of inthe
inthe

hi,
you can do this to press the buuton where handle is its handle gotten via findwindow:

sendmessage(handle,WM_LBUTTONDOWN,0,0);
sendmessage(handle,WM_LBUTTONUP,0,0);

(that is telling the buuton the mouse clicked it)
Regards Barry
howdy,

actually, inthe's answer is a tad over the top....i'm doing the exact some thing for a program i'm working on right now..
this will do the exact same thing as inthe's answer, but it does it in one line:

sendmessage(YOUR_HANDLE, BM_CLICK, 0, 0);

hth,

x
mmm.
wouldnt really call 2 lines over the top .. ;-)
I didn't know that
sendmessage(YOUR_HANDLE, BM_CLICK, 0, 0);  would work.

I have been using
PostMessage( WindowHandle,
                      wm_Command,
                      DlgID, {of Button},
                      MakeLong(GetDlgItem(WHandle, DlgID), BN_Clicked));
all these days.
Avatar of frangers99

ASKER

Ok you're both right, but what do you do if the window that's popping up is showmodal (ie, the button has to be pressed before the next instruction of your code is run) what happens then? I tried both pieces of code and they don't work with showmodal forms (such as dialog boxes).

Thanks both of you for your help. But this final helper will have me set.
Are you asked about external application?

Cheers
Igor.
ooh..

this is interesting...i have never tried to automatically press dialog buttons...

there are several programs which do this (eg: Buzz Orf)

is there a "GetDialogWindow" APi call?? ;-P~

-x

well, you can use a timer to do that. e.g.

Timer1.Interval := Whatever;
Timer1.Enabled := true;
YourForm.ShowModal;
....


//and in your Timer1.Timer event
Timer1.Enabled := false;
WindowHandle := FindWindow(ClassName, Caption);
BtnHandle := GetDlgItem(WHandle, DlgID);

PostMessage( WindowHandle, wm_Command,  DlgID,
                        MakeLong(BtnHandle , BN_Clicked));

You might try this function
....
mouse_event
....
my reading of the help file suggests this will do what you want. (use the absolute coords)
there is also a
keybd_event
if you are pressing defaul buttons this will work too.
The target app should be set active.

Alex
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Adjusted points from 30 to 50
Barry I am going to try your answer sorry for the showmodal trouble but i'm gonna boost the points up 20 and i'll try this code this arvo and if it's right, which i'm sure it will be then you got yourself the points
sorry to change the question a little but both solutions are excellent, thanks to everybody who contributed