Solved

Obtaining  a hanldle from a form, for use in PostMessage

Posted on 2000-04-06
10
244 Views
Last Modified: 2010-04-02
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

0
Comment
Question by:AntBon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 5

Expert Comment

by:proskig
ID: 2689060
Use ChildWindowFromPoint to find out handle to a window which is under your mouse cursor
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2689243
Can't you use 'mouse_event()'?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2689369
Yes, mouse_event() would be the way to go.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Rheingold
ID: 2689496
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
 
LVL 22

Expert Comment

by:nietod
ID: 2689572
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 2689586
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
 
LVL 22

Expert Comment

by:nietod
ID: 2689623
>> 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
 

Author Comment

by:AntBon
ID: 2690891
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
 
LVL 1

Accepted Solution

by:
jbodom earned 50 total points
ID: 2692356
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 2692527
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question