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
    402

    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
    402

    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
    1396

    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. . . .


  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
    1396

    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. . . .

    Thanks to blaggard

    Zoots (13th August 2014)  


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

    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. Floppy problem
    By urbsy in forum PC Problems
    Replies: 8
    Last Post: 7th September 2002, 12:04 AM
  2. F12002 Problem
    By shawtek in forum Microsoft Consoles
    Replies: 9
    Last Post: 31st August 2002, 10:20 AM
  3. Problem with Compaq Armada E500 Laptop
    By Mr Olympia in forum PC Problems
    Replies: 2
    Last Post: 29th August 2002, 02:40 PM
  4. real audio recording problem
    By flypitcher in forum Music Factory
    Replies: 3
    Last Post: 28th August 2002, 11:25 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
  •