PDA

Click to See Complete Forum and Search --> : Mouse Tracking


mruncola
Aug 20th, 2002, 10:01 PM
Is there any way to get where on the form the mouse is and move an image accordingly.


Type POINTAPI 'Declare types
x As Long
y As Long
End Type

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 'Declare API



This is just returning X,Y position across the screen not just the form. How can i get it to limit itself to just the form and then get the placement based on the x, y?

Thanks.

Amithran
Aug 20th, 2002, 10:15 PM
Simple subtraction.

formX = mouseX - form1.left
formY = mouseY - form1.top

formMaxX = form1.left + form1.width
formMaxY = form1.top + form1.height



or something along those lines.

Sastraxi
Aug 20th, 2002, 11:17 PM
Unfortunately this won't work as the .top and .left properties are the complete top left... meaning to the top-left of the ICON even. You can use GetWindowRect of the child window to the form, I believe.

Amithran
Aug 21st, 2002, 12:11 AM
or, you can make a command(cmdTopLeft), place it in the top left of form and set to not visible.

mouseX - cmdTopLeft.left
mouseY - cmdTopLeft.top

cose enough :)

Zaei
Aug 21st, 2002, 12:43 AM
Use the ScaleTop and ScaleLeft properties of a form to get it's client upper left and right. Similarly, use the ScaleWidth and ScaleHeight properties to get the width and height of the client area. Finally, use the ScaleX and ScaleY functions of the form to scale the .Scale... properties from twips to pixels, like so:

X = Form1.ScaleX(Form1.ScaleLeft, vbTwips, vbPixels)


Z.