Simulate Human Clicks

I have this program I use to connect to the Internet via GPRS and I want the PC to go online after a power failure so the first and obvious step is to add this program to the Start menu.

Problem is the program doesn't has a 'connect on startup' option, you have to manually click a Connect button it has. How could I simulate the human click? Are there any API calls that could bring the program window to the XP 'Foreground' and later click on a certain Screen position?

Ty in advance.
jpp1jpp1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

butterhookCommented:
You can Subclass the window and access the button's click, you wouldn't even need to bring it to the foreground. It's quite complicated and I don't quite know how to do it, but search for 'Subclassing' and you may find some useful info.

You will need to get the handle (hWnd) for the application window and for the button within that window.

If you have Visual Studio 6 you can use the Spy++ application to find these values.
0
aluayCommented:
My solution is that you do this:
1. Add the program to the registry startup with a command line argument...
for e.g.
AT HKEY_CURRENT_USER and the subkey
Software\Microsoft\Windows\CurrentVersion\Run

add your MyApp.Exe 1

2. Read this command line argument in Visual basic...if its set, then call the connect method
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can't subclass an external application with VB (at least not without any externall DLLs written in another language).
You don't need subclassing to accomplish this anyways...

butterhook is right in that you need an hWnd for the external app though.  You can use the FindWindow() API to get a handle to the application based on its window title.  This requires an exact match.  Does the application have a static, non-changing title that is predictable?  If it doesn't then you can also use the FindWindow() API to find the window based on its classname (assuming the classname is unique to this app).  Use the Spy++ tool that comes with Visual Studio 6 to view the classname of the window.  If you don't have Spy++, do a Google search for the free tool called "WinSpector" (I've used it before and it seems to be safe and free of spyware).

Here ias a PAQ that demonstrate the FindWindow() API:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20919239.html


There are two basic ways to go about this:

(1) Simulate a mouse click by pressing the mouse button up/down at a specific location onscreen.  The location can be relative to the programs location on screen.  This is dependent upon the button being in the same location everytime the application is run.  Is this the case?  

If you use this method, then you can pass the hWnd for your window (determined by the FindWindow() call) to the GetWindowRect() API.  This API will give you the location onscreen of a window based on the passed in hWnd.  Once you have the location, you can simulate a mouse click at a predetermined offset using the mouse_event() API.

Here is a PAQ that demonstrates the GetWindowRect() API:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_21567355.html

Here is a PAQ that demonstrates the mouse_event() API:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21515914.html


(2) Send a message directly to the button in the application using SendMessage()/PostMessage().  This requires you to first find the main window handle and then drill down thru the hierarchy of child windows to find the correct button.  This can be tricky depending upon how the application was built.  Spy++/WinSpector are necessary to figure out the correct relationships between windows.  You can use the FindWindowEx() and/or GetNextWindow() APIs in combination to determine the hWnd of your button.  This approach is the more difficult of the two if you don't have experience in this kind of thing (it is also more difficult to describe how to accomplish since we often don't have the application in front of us to walk you thru it!).

Let us know if you want to try this approach instead...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jpp1jpp1Author Commented:
Yes, it's an external application and the window's caption doesn't change so I'm gonna try your 1st approach.
0
aluayCommented:
i guess my solution is better,
instead of adding the application to the start menu, add it to the statr list of the registry....with a parameter in the command line....
easy and to the point....

0
jpp1jpp1Author Commented:
Aluay I'm trying to manage an external application, it's not mine
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
@aluay...

I'm pretty sure the application in question was NOT written by jpp1pp1...and therefore this is not an option.

He confirmed in the comment just before yours that it is an "external application".
0
jpp1jpp1Author Commented:
Worked like charm ty Idle mind
0
aluayCommented:
i am sorry guys...i recieved the comments so late.....
best luck
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You need help ironing out the code jpp1jpp1?  

Or is it all done?...
0
jpp1jpp1Author Commented:
I'd have sweared I accepted yesterday your answer. It's working great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.