Problem with mousemove event during mousedown in VB6

Thread: Problem with mousemove event during mousedown in VB6

  1. BigBird's Avatar

    BigBird said:

    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. BigBird's Avatar

    BigBird said:

    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
     
  3. blaggard's Avatar

    blaggard said:

    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. blaggard's Avatar

    blaggard said:

    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. ]
     
  5. Zoots's Avatar

    Zoots said:

    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.