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
Solved

Simulating the mouse

Posted on 1998-02-12
6
978 Views
Last Modified: 2011-10-03
Im Using Delphi 3 in a Windows95 Enviroment:

Is it posible to activate other applications and do mouse events in those application(Press buttons, Menus and other).

I want things to happen like if i was manually moving the mouse around my screen, but i want to do it from my application.

I dont know the handle of the window i want to activate, it depends on the position af the mouse.

I have tried sending a WM_LBUTTONDOWN message to another application by pressing a button(Not mouse button), but the message seem to be send to my application and not to the other application (When using Winsight). Winsight returns something like this:
0000:00000528 (other application name) WM_LBUTTONDOWN (position) Dispatched
but only when i mark the process of my application, not (other application)

I hope someone understand this question !

PS. I'm not very good at API Calls, so i would like some sample code


0
Comment
Question by:kwang080897
6 Comments
 

Author Comment

by:kwang080897
ID: 1359069
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359070
You always need to know the handle of that window, eg. example minimizing another application from delphi.

First you need to get the HWND (Window Handle see the WinAPI help) of the
window you want to close (The subject of another thread here.) Then try
this Windows API routine. SendMessage( hWnd, WM_SIZE, SIZE_MINIMIZED, 0);
This sends the message to the window in hWnd, that the user pressed
the minmize box or selected it from the system menu.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359071
If you don't know the handle, but the caption, you can use did :

You can send the application a WM_QUIT message;

Example:
PostMessage(FindWindow(Nil, 'window caption'), WM_SIZE, SIZE_MINIMIZED, 0);

So what you need to do is :
 
PostMessage(FindWindow(Nil, 'window caption'), WM_LBUTTONDOWN, wParam, lParam)

But I think that you need the handle of a button, when you use WM_LBUTTONDOWN. Like :

PostMessage(BitBtn1.Handle, WM_LBUTTONDOWN, Word(0), LongInt(0)) ;

Try to send a mouse click message.

Where "window caption" is the caption of the window that you
are sending the message to.

Regards, Zif.
0
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.

 
LVL 2

Expert Comment

by:mvz121697
ID: 1359072
Here's some code i used to automate PC-Anywhere.
I searched for a button-window in a dialog.
I did a lot of testing with the GetWindow calls,
to try to find the right window-handle.
The name CONNSTAT is the classname of the PCA- main window. I looked it up with a spy-utility like winsight.
(BTW: You can not hard-code the window-handle-numbers.
Windows assigns them, and they can be different every time
the p[rogram run's)

procedure TForm1.Button1Click(Sender: TObject);
var
  n,w1:integer;
  SI: TStartupInfo;
  PI: TProcessInformation;
  Proc,WinHandle: THandle;
  c:string;
begin
  WinHandle := FindWIndow( 'CONNSTAT', nil );
  if(0 <> WinHandle )then
  begin
       W1:=GetWindow(WinHandle,GW_CHILD);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       SendMessage(W1,WM_KEYDOWN,32,0);
       SendMessage(W1,WM_KEYUP,32,0);
   end;

0
 

Author Comment

by:kwang080897
ID: 1359073
My problem is:

I have to application running:
First application creates a file on a Network server, that tells the other application what to do

The other is picking up the file and doing the things  commanded in the file,  so i can control that maschine remote. Therefore i dont know the windows captions, and the button names, I want to be able to move the mouse around and click like if i was sitting infront of that machine.(I dont need to see the screen input, i'll solve that problem later) .

I dont think I can use the answer i got, if i can please explain

Thank you for trying - hope you can help me futher
PS. I will not be able to respont to comments and answer before Monday

0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 400 total points
ID: 1359074
You can use WindowFromPoint to get a location of a window at a specific point. After that, you can get the child window of that point using ChildWindowFromPoint or ChildWindowFromPointEx. Then you can use SendMessage to send comamnds to the parent or child windows
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
How to define IfThen functions in one common unit? 4 58
creating threads in delphi 1 130
FMX TEdit KeyUp handler detecting  "enter" key 4 13
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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