• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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.
0
TonyJix
Asked:
TonyJix
  • 6
  • 5
  • 2
1 Solution
 
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
 
HardiCommented:
I think from that sample code you can simulate mouse button down, then mouse move, then mouse button up?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
diniludCommented:
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:
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now