Link to home
Start Free TrialLog in
Avatar of TonyJix
TonyJix

asked on

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.
Avatar of Hardi
Hardi

Hi Tony

See this (see Simulations)
http://delphi.about.com/od/vclusing/a/mouseadvanced.htm
Avatar of TonyJix

ASKER

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.
I think from that sample code you can simulate mouse button down, then mouse move, then mouse button up?
Avatar of TonyJix

ASKER

Good one.. brb
Avatar of TonyJix

ASKER

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.
Oh... sorry I have no idea about that... what application is it?
May be someone else can help?
ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tony, dinilud only used the functions I gave you.
And why didn't your code only work on Notepad before?
Sorry dinilud, no offence.
Avatar of TonyJix

ASKER

Yes, maybe. I shouldve split... The code was easier to use though.

If you post your same solution here: https://www.experts-exchange.com/questions/22714749/SetWindowPos-alternative.html?cid=239

Then I will give you points there hardi.
Oh so you open up 2 questions for this
Ok thank you :-D
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;
Avatar of TonyJix

ASKER

It's the ABSOLUTE or MOUSEEVENTF_MOVE that's needed. Thanx though.