Solved

Obtaining  a hanldle from a form, for use in PostMessage

Posted on 2000-04-06
10
224 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

831 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