Close

Results 1 to 5 of 5
  1. #1
    DF VIP Member
    BigBird's Avatar
    Join Date
    Mar 2005
    Location
    WALES
    Posts
    2,003
    Thanks
    1,412
    Thanked:        1,585
    Karma Level
    330

    Help Problem with mousemove event during mousedown in VB6

    Got a problem with a mousemove event in my PTZ camera controller created with VB6.

    It contains a picturebox as seen in the image below, which is used as a virtual joystick.



    I have created a boolean flag called IsMouseDown so that any mouse move event while the mouse is down will cause the camera to move in a different direction and at different speeds depending on the position and distance from the centre of the picturebox. Apart from setting the flag the mousedown event also moves the camera.

    It works great . . .just like a joystick. The problem is that if the mouse moves outside the picturebox while the mouse is down, the camera still follows the mouse movement. This only happens if the mousedown event is initially triggered in the picturebox. So if the mousedown event only applies when the mouse is over the picturebox as it should be, why is the mousemove event still active when it strays outside the picturebox because they are both related to the picturebox component.

    ----------------------------------------------------------------------------------------------------------------------
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

    IsMouseDown = True 'Sets boolean flag IsMouseDown to true

    PanPosition = (x)
    TiltPosition = (y)

    If PanPosition < 0 Then 'Selects the pan direction. Center of Picturbox1 is 0. Left of center selects pan left and vice versa.
    CamData(3) = &H4
    ElseIf PanPosition > 0 Then
    CamData(3) = &H2
    Else: CamData(3) = 0
    End If

    If TiltPosition < 0 Then 'Selects the tilt direction. Center of Picturbox1 is 0. Above center selects tilt up and vice versa.
    CamData(3) = CamData(3) + &H10
    ElseIf TiltPosition > 0 Then
    CamData(3) = CamData(3) + &H8
    Else: CamData(3) = CamData(3) + 0
    End If

    CamData(4) = Abs(PanPosition) 'Removes the minus sign and sends x and y mouse position values to the CamData array-
    CamData(5) = Abs(TiltPosition) 'and uses this data to select camera pan/tilt speed.

    SendOutput

    End Sub

    ----------------------------------------------------------------------------------------------

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

    If IsMouseDown = True Then 'Checks IsMouseDown boolean flag

    PanPosition = (x)
    TiltPosition = (y)

    If PanPosition < 0 Then 'Selects the pan direction. Center of Picturbox1 is 0. Left of center selects pan left and vice versa.
    CamData(3) = &H4
    ElseIf PanPosition > 0 Then
    CamData(3) = &H2
    Else: CamData(3) = 0
    End If

    If TiltPosition < 0 Then 'Selects the tilt direction. Center of Picturbox1 is 0. Above center selects tilt up and vice versa.
    CamData(3) = CamData(3) + &H10
    ElseIf TiltPosition > 0 Then
    CamData(3) = CamData(3) + &H8
    Else: CamData(3) = CamData(3) + 0
    End If

    CamData(4) = Abs(PanPosition) 'Removes the minus sign and sends x and y mouse position values to the CamData array-
    CamData(5) = Abs(TiltPosition) 'and uses this data to select camera pan/tilt speed.

    SendOutput

    Else

    StopAllMovement

    End If

    End Sub

    --------------------------------------------------------------------------------------------

    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

    IsMouseDown = False 'Sets boolean flag IsMouseDown to false

    End Sub

    -------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------

    Tried adding this below so that if the mouse moves over the form or the picturebox lost the focus it should stop all movement but it makes no difference

    --------------------------------------------------------------------------------------------

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    StopAllMovement

    End Sub

    ----------------------------------------------------------------------------------------------

    Private Sub Picture1_LostFocus()

    StopAllMovement

    End Sub

    -------------------------------------------------------------------------------------------------

    Not really part of the above problem but don't fully understand why I had these problems below either:

    I have had to repeat much of the same code for the mousedown and mousemove event. When I tried to create it as a seperate sub and called from each event it wouldn't work at all (no camera movement).

    Also tried the mousemove as a 'Do While IsMouseDown' loop but could only manage to get it to work using the 'If IsMouseDown Then' loop even though Do While seems to make more sense. If I use a Do While loop the camera doesn't stop when the mouse is released even though I wrote it as Do While ISMouseDown = True. It seemed to get stuck within the loop and didnt see the boolean flag change with the mouseup event.

    Hope I've explained it ok. (">

  2. #2
    DF VIP Member
    BigBird's Avatar
    Join Date
    Mar 2005
    Location
    WALES
    Posts
    2,003
    Thanks
    1,412
    Thanked:        1,585
    Karma Level
    330

    Default Re: Problem with mousemove event during mousedown in VB6

    Sorted now. Was sent an impressive solution that traps the mouse inside the picturebox. Works exactly as I want it to now.

    Have attached the solution which may be useful for anyone who wants to contain the mouse within a picturebox during mousedown in VB6. (">
    Attached Files Attached Files

  3. #3
    DF VIP Member
    blaggard's Avatar
    Join Date
    Jan 2001
    Location
    South London
    Posts
    15,748
    Thanks
    1,517
    Thanked:        1,902
    Karma Level
    1504

    Default Re: Problem with mousemove event during mousedown in VB6

    Quote Originally Posted by ir0n87 View Post
    Hi BigBird, I'm looking for a software similar to control my PTZ Pelco D camera... Can u share your source?
    You've been posting loads of crap to boost your count and now you are digging up an old thread (last post over two years ago) can you think of a reason I should not ban you?
    If at first you don't succeed.....redefine success. . . .

    [Only registered and activated users can see links. ]

  4. #4
    DF VIP Member
    blaggard's Avatar
    Join Date
    Jan 2001
    Location
    South London
    Posts
    15,748
    Thanks
    1,517
    Thanked:        1,902
    Karma Level
    1504

    Default Re: Problem with mousemove event during mousedown in VB6

    Well I've read through your posts and you got to 15 but obviously still couldn't access the file you wanted. . .
    If at first you don't succeed.....redefine success. . . .

    [Only registered and activated users can see links. ]

    Thanks to blaggard

    Zoots (13th August 2014) 


  5. #5
    DF Jedi Zoots's Avatar
    Join Date
    Oct 2010
    Location
    Hoth
    Posts
    3,329
    Thanks
    1,648
    Thanked:        1,321
    Karma Level
    364

    Default Re: Problem with mousemove event during mousedown in VB6

    Quote Originally Posted by ir0n87 View Post
    . Can u share your source?
    Quote Originally Posted by ir0n87 View Post
    If givin my opinion in my work field is bad...
    Bollocks.

Similar Threads

  1. [NEW] What would you do? In event of doomsday?
    By CallmeGoose in forum The Dog and Duck
    Replies: 76
    Last Post: 9th September 2012, 08:04 PM
  2. The Event
    By CallmeGoose in forum TV Talk
    Replies: 12
    Last Post: 31st May 2011, 12:01 AM
  3. The Event
    By reverend in forum TV Talk
    Replies: 62
    Last Post: 18th March 2011, 02:02 PM
  4. Todays Event
    By cronus71 in forum The Dog and Duck
    Replies: 4
    Last Post: 1st July 2005, 07:21 PM

Social Networking Bookmarks

Posting Permissions

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