|
-
May 11th, 2013, 10:04 PM
#7
Thread Starter
Member
Re: Sending a click to exact coordinates in an inactive program
 Originally Posted by dunfiddlin
When the form is inactive you cannot seek a point on the form, you must seek a point on the screen. Now there are two problems. If the form has become covered then even an accurate click won't work. And you cannot convert the form co-ordinates to a screen point using PointToScreen because the form's co-ordinate system is not accessible. So you have to record the screen position while the form is active, ensure that the form is not moved or covered, then pray that the cursor isn't being moved when the timing tick occurs because it will immediately override your cursor positioning and that the form is woken in time to process the events responding to the click.
For all those reasons you simply wouldn't do this in real life. If you wanted to access an inactive form programatically you would always activate it first so that you can be sure of where it's at. And you would only do a move cursor and click simulation as a last resort in any case.
One thing I did notice, is that you are using the top left corner as your cursor target which is always a bad idea as it only takes an error of 1 pixel in 3/4 of all possible directions to miss the control altogether. You should always aim for a point inside the control, preferably at its centre.
Thanks for the explanation. I think my professor just assigned me this because I'm ahead of my class and he was looking to stump me. Anyways I found a solution to my issue.
me.cursor.position returns the correct points to use with the postmessage function. However upon using it (me.cursor.position.tostring) I got a warning that reads:
Code:
Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
My app still runs fine and displays the coordinates so I'm looking into what this means. Thanks again for responding.
And I know I didn't ask for this (and neither did my professor), but to click the control without a coordinate you can just use the control's handle in the hWnd parameter.
Last edited by code; May 11th, 2013 at 10:25 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|