Results 1 to 3 of 3

Thread: Automatic Picture Movement

  1. #1

    Thread Starter
    Hyperactive Member Matt-D's Avatar
    Join Date
    Nov 1999
    Location
    Mettmann, Germany
    Posts
    305

    Post

    I want, that a picturebox moves up, when the mouse is in
    an specific area (like the bottom of the screen). But the imortant thing is, that the mouse hasn't to be moved.

    T think it's s.th. like this (Here I have to move the
    mouse and that's, what I don't want!!!!)

    Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Y > 6000 then
    Picture1.Top = Picture1.Top - 10
    End If
    End Sub

    Perhaps I have to use a loop ?????

    I hope you understand my problem, Matt

    16:29 Germany

    Edited by Matt-D on 02-25-2000 at 11:25 AM

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    This isn't tested Matt, but if you have any problems let me know:

    In a module:
    Code:
    Type POINT_TYPE
      x As Long
      y As Long
    End Type
    
    Public Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
    In a timer in your form:
    Code:
    Dim coord As POINT_TYPE  ' receives coordinates of cursor
    Dim retval As Long  ' return value
    
    retval = GetCursorPos(coord)  ' read cursor location
    If coord.y > 6000 then
    picture1.top = picture1.top - (coord.y - 6000)
    End If

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Wade's idea is a good one and will work, but you need to make some modification to the code, first of all, the Coords are returned in Pixels, so you'll need to do a Conversion, also, the Coords are returned relative to the Top, Left Corner of the Screen, so you'd need to Adjust them to be from the Top, Left of your Form, you can do this with the ScreenToClient API, ie.

    Code:
    Private Type POINTAPI
      x As Long
      y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) As Long 
    Private Declare Function ScreenToClient Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    Private Sub Timer1_Timer()
        Dim tPOINT As POINTAPI
        Call GetCursorPos(tPOINT)
        Call ScreenToClient(hWnd, tPOINT)
        If tPOINT.y > ScaleY(6000, vbTwips, vbPixels) Then Picture1.Top = Picture1.Top - (ScaleY(tPOINT.y, vbPixels, vbTwips) - 6000)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width