Obtaining a hanldle from a form, for use in PostMessage

I am using Borland Builder C++ 4.

I have created a form, various other stuff. I want to make the mouse move automatically to a certain part of the screen, and then click on that part.

Ok. I can make the mouse move, but i do not know how to make it click, i beleive i need to 'PostMessage', but i dont know where to obatain the windows handle from & then how toi use it


Help

AntBonAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jbodomConnect With a Mentor Commented:
Here's one way to do what you want to do or at least what I think you want.  This is not the 'proper' way to do this but it'll work.

Place a TButton component on the form and set the Visible property to false.  When the mouse reaches the coordinates that you wish to perform your action then simply:

Button1->Click();

And in the OnClick() event of the button perform the actions you need.

There are other controls that have the Click() function.  Just do a search for click in the help file.  TMediaPlayer also has the Click() function to simulate a mouse click if by chance you're using it.



0
 
proskigCommented:
Use ChildWindowFromPoint to find out handle to a window which is under your mouse cursor
0
 
ZoppoCommented:
Can't you use 'mouse_event()'?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
nietodCommented:
Yes, mouse_event() would be the way to go.
0
 
RheingoldCommented:
You could use the Windows API "WindowFromPoint". You need a POINT as only parameter and the return value is the handle of the window at that point.
0
 
nietodCommented:
I would agrre that would be the way to go if you need to find out what window is at a particular point, but in this case that information is really not needed.  mouse_event() will do a better job and be easier to use.
0
 
ZoppoCommented:
I agree with nietod ... only thing you'll have to take care is to calculate between screen pixels and socalled 'mickeys' (for description what 'mickeys' are see help for mouse_event), i.e.:

// this code moves mouse to postition 100x100
int xMax = GetSystemMetrics( SM_CXSCREEN );
int yMax = GetSystemMetrics( SM_CYSCREEN );
int x = 100; // x-position in pixels
int y = 100; // y-position in pixels
x = x * 65536 / xMax; // x-position in mickeys
y = y * 65536 / yMax; // x-position in mickeys
mouse_event(
 MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,
 x,
 y,
 0,
 0
 );

ZOPPO
0
 
nietodCommented:
>> I agree with nietod
I was agreeing with you.  So is that infinitely recusive agreement or is that infinitely circular agreement  I can't remember which is which?  :-)
0
 
AntBonAuthor Commented:
What i really need in lamens terms is the syntax (i think)

Here is the code i have so far

sndPlaySound(String("Help"+String(Response)+String(".wav")).c_str(),SND_SYNC);

DestX=HotSpotList->HotSpot[RoadSign[i]]->HotX;

DestY=HotSpotList->HotSpot[RoadSign[i]]->HotY+DestY_OFFSET;

AutoCursor->MoveCursor(X,Y,DestX,DestY,10,HotSpotList);
         
PostMessage (Handle,WM_MBUTTONDOWN,0,0);
//PostMessage(Handle,WM_LBUTTONDOWN,0,0);
// Application->ProcessMessages();


As you can see i have the source and dest mouse co-ordinated, i then call the 'MoveCursor' (Supplied by my lecuturer) to move to the destination co-ordinates.  THEN what i am trying to do is post a 'Mousebutton Click' event so the system will effectivly push the button on the screen for me.

I am not sure if the syntax is right, i just dont know how to fill the parameters in. I have tried
TForm->handle and that dont work either..

PLEASE Help

cheers
0
 
ZoppoCommented:
Hi AntBon,

// this simulates a left mouse button press without moving
mouse_event(
 MOUSEEVENTF_LEFTDOWN,
 0,
 0,
 0,
 0
 );

// this simulates a left mouse button release without moving
mouse_event(
 MOUSEEVENTF_LEFTUP,
 0,
 0,
 0,
 0
 );


to nietod: LOL ... couldn't reply yesterday coz I got som aggrement deadlock    :-)


ZOPPO
0
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.

All Courses

From novice to tech pro — start learning today.