home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / LaVolpe_Wo2107533262008.psc / clsTrackingHandle.cls < prev    next >
Text File  |  2008-02-24  |  5KB  |  154 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsTrackingHandle"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private Declare Function ReleaseCapture Lib "user32.dll" () As Long
  16. Private Declare Function GetCapture Lib "user32.dll" () As Long
  17.  
  18. Private m_Mode As Long
  19.  
  20. ' cached values to be passed when Shift key toggled
  21.     Private m_LastX As Single
  22.     Private m_LastY As Single
  23.     Private m_Shift As Integer
  24.  
  25. Private m_isActive As Boolean               ' whether tracking or not
  26. Private m_CallBack As ITrackingCallback     ' reference back to clsWATracker
  27.  
  28. Private WithEvents theHandle As VB.PictureBox ' our handle
  29. Attribute theHandle.VB_VarHelpID = -1
  30.  
  31. Public Function CreateHandle(ByVal HANDLESIZE As Long, hostContainerParent As Object, ByVal handleName As String, ByVal Mode As Long, CallBackObj As ITrackingCallback, hostContainer As Object) As Boolean
  32.  
  33.     If hostContainerParent Is Nothing Then Exit Function
  34.     
  35.     On Error Resume Next
  36.     Set theHandle = hostContainerParent.Controls.Add("VB.PictureBox", handleName, hostContainer)
  37.     m_isActive = False
  38.     
  39. ExitRoutine:
  40.     If Err Then
  41.         Err.Clear
  42.         Stop
  43.         Resume
  44.     Else
  45.         m_Mode = Mode
  46.         With theHandle
  47.             .ScaleMode = vbPixels
  48.             .Width = HANDLESIZE
  49.             .Height = HANDLESIZE
  50.             .Appearance = 0
  51.             .BorderStyle = 1
  52.             .Enabled = True
  53.             .MousePointer = vbCrosshair
  54.             .ZOrder
  55.         End With
  56.         Set m_CallBack = CallBackObj
  57.         CreateHandle = True
  58.     End If
  59. End Function
  60.  
  61. Public Property Get This() As VB.PictureBox
  62.     Set This = theHandle
  63. End Property
  64. Public Property Set This(theObject As VB.PictureBox)
  65.     Set m_CallBack = Nothing
  66.     Set theHandle = theObject
  67. End Property
  68.  
  69. Public Property Get CallBackObject() As ITrackingCallback
  70.     Set CallBackObject = m_CallBack
  71. End Property
  72. Public Property Set CallBackObject(theObject As ITrackingCallback)
  73.     Set m_CallBack = theObject
  74. End Property
  75.  
  76. Public Property Get Mode() As eTrackingModes
  77.     Mode = m_Mode
  78. End Property
  79. Public Property Let Mode(newMode As eTrackingModes)
  80.     m_Mode = newMode
  81. End Property
  82.  
  83. Private Sub Class_Terminate()
  84.     Set m_CallBack = Nothing
  85.     Set theHandle = Nothing
  86. End Sub
  87.  
  88. Private Sub theHandle_KeyDown(KeyCode As Integer, Shift As Integer)
  89.     If KeyCode = vbKeyEscape Then
  90.         m_isActive = False
  91.         If GetCapture = theHandle.hwnd Then ReleaseCapture
  92.         Call m_CallBack.TrackingTerminated(vbNullString, True)
  93.     ElseIf m_isActive Then
  94.         If KeyCode = vbKeyShift Then
  95.             If (m_Shift And vbShiftMask) = 0& Then
  96.                 m_Shift = m_Shift Or vbShiftMask
  97.                 Call m_CallBack.TrackingPointChanged(vbNullString, m_LastX, m_LastY, m_Shift, m_Mode, False)
  98.             End If
  99.         End If
  100.     End If
  101. End Sub
  102.  
  103. Private Sub theHandle_KeyUp(KeyCode As Integer, Shift As Integer)
  104.     If m_isActive Then
  105.         If KeyCode = vbKeyShift Then
  106.             If (m_Shift And vbShiftMask) = vbShiftMask Then
  107.                 m_Shift = (m_Shift And Not vbShiftMask)
  108.                 Call m_CallBack.TrackingPointChanged(vbNullString, m_LastX, m_LastY, m_Shift, m_Mode, False)
  109.             End If
  110.         End If
  111.     End If
  112. End Sub
  113.  
  114. Private Sub theHandle_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  115.     If Button = vbLeftButton Then
  116.         If Not m_CallBack Is Nothing Then
  117.             m_LastX = x: m_LastY = y: m_Shift = Shift
  118.             If m_isActive Then
  119.                 Call m_CallBack.TrackingPointChanged(vbNullString, x, y, Shift, m_Mode, False)
  120.             Else
  121.                 m_isActive = True
  122.                 Call m_CallBack.TrackingStarted(vbNullString, x, y, m_Mode)
  123.             End If
  124.         End If
  125.     End If
  126. End Sub
  127.  
  128. Private Sub theHandle_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  129.     On Error GoTo ExitRoutine
  130.     Dim bCancel As Boolean
  131.     If m_isActive Then
  132.         m_LastX = x: m_LastY = y: m_Shift = Shift
  133.         Call m_CallBack.TrackingPointChanged(vbNullString, x, y, Shift, m_Mode, bCancel)
  134.         If bCancel Then m_isActive = False
  135.     End If
  136.     
  137. ExitRoutine:
  138.     If Err Then
  139.         Err.Clear
  140.         m_isActive = False
  141.     End If
  142. End Sub
  143.  
  144. Private Sub theHandle_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  145.     If m_isActive Then
  146.         If Button = vbLeftButton Then
  147.             m_isActive = False
  148.             Call m_CallBack.TrackingTerminated(vbNullString, False)
  149.         End If
  150.     End If
  151. End Sub
  152.  
  153.  
  154.