Moving the Mouse

Hello,

I need to move the window of another application, but SetWindowPos and MoveWindow don't work.

I had the idea of moving the mouse to the title bar of the application, then hold the left mouse button while moving the mouse (all programatically). This way I am able to move the application anyway.

Anyone any idea how to do a mouse click (let it hold) and move the mouse at the same time?

Thank you.
TonyJixAsked:
Who is Participating?
 
diniludConnect With a Mentor Commented:
procedure MyDragWindowToPos(pHandle:HWND;pPos:TPoint);
const XDiff=100; YDiff=10;

var R:TRect;
begin
  GetWindowRect(pHandle,R);
  SetCursorPos(R.Left+XDiff,R.Top+YDiff);

  Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, 0, 0, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_MOVE, pPos.X+XDiff , pPos.Y+YDiff, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_LEFTUP,0, 0, 0, 0) ;
end;
0
 
HardiCommented:
Hi Tony

See this (see Simulations)
http://delphi.about.com/od/vclusing/a/mouseadvanced.htm
0
 
TonyJixAuthor Commented:
Hi,

Not what I am looking for. I need it to click button and move mouse at the same time. Otherwise you won't drag the window.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
HardiCommented:
I think from that sample code you can simulate mouse button down, then mouse move, then mouse button up?
0
 
TonyJixAuthor Commented:
Good one.. brb
0
 
TonyJixAuthor Commented:
Not doing anything with this App...

So weird.. I can get the Handle of the window, I move the moust to the titlbar, then I drag it. But nothing happens. If I use the same code on Notepad it works fine.

It must have some anti-interfere code hehe.
0
 
HardiCommented:
Oh... sorry I have no idea about that... what application is it?
May be someone else can help?
0
 
HardiCommented:
Tony, dinilud only used the functions I gave you.
And why didn't your code only work on Notepad before?
0
 
HardiCommented:
Sorry dinilud, no offence.
0
 
TonyJixAuthor Commented:
Yes, maybe. I shouldve split... The code was easier to use though.

If you post your same solution here: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22714749.html?cid=239

Then I will give you points there hardi.
0
 
HardiCommented:
Oh so you open up 2 questions for this
Ok thank you :-D
0
 
diniludCommented:
i got one error.
Without checking correctly don't accept any answer.



procedure MyDragWindowToPos(pHandle:HWND;pPos:TPoint);
 const XDiff=100; YDiff=10;
 var R:TRect;
     Rx,Ry:Word;
begin
  GetWindowRect(pHandle,R);
  SetCursorPos(R.Left+XDiff,R.Top+YDiff);

  Rx:= Round((pPos.X+XDiff)*65535/Screen.Width);
  Ry:= Round((pPos.Y+YDiff)*65535/Screen.Height);

  Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, 0, 0, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, Rx , Ry, 0, 0) ;
  Mouse_Event(MOUSEEVENTF_LEFTUP,0, 0, 0, 0) ;
end;
0
 
TonyJixAuthor Commented:
It's the ABSOLUTE or MOUSEEVENTF_MOVE that's needed. Thanx though.
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.