Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Obtaining  a hanldle from a form, for use in PostMessage

Posted on 2000-04-06
10
Medium Priority
?
252 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 150 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

877 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