Private Declare Function ReleaseCapture Lib "user32.dll" () As Long
Private Declare Function GetCapture Lib "user32.dll" () As Long
Private m_Mode As Long
' cached values to be passed when Shift key toggled
Private m_LastX As Single
Private m_LastY As Single
Private m_Shift As Integer
Private m_isActive As Boolean ' whether tracking or not
Private m_CallBack As ITrackingCallback ' reference back to clsWATracker
Private WithEvents theHandle As VB.PictureBox ' our handle
Attribute theHandle.VB_VarHelpID = -1
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
If hostContainerParent Is Nothing Then Exit Function
On Error Resume Next
Set theHandle = hostContainerParent.Controls.Add("VB.PictureBox", handleName, hostContainer)
m_isActive = False
ExitRoutine:
If Err Then
Err.Clear
Stop
Resume
Else
m_Mode = Mode
With theHandle
.ScaleMode = vbPixels
.Width = HANDLESIZE
.Height = HANDLESIZE
.Appearance = 0
.BorderStyle = 1
.Enabled = True
.MousePointer = vbCrosshair
.ZOrder
End With
Set m_CallBack = CallBackObj
CreateHandle = True
End If
End Function
Public Property Get This() As VB.PictureBox
Set This = theHandle
End Property
Public Property Set This(theObject As VB.PictureBox)
Set m_CallBack = Nothing
Set theHandle = theObject
End Property
Public Property Get CallBackObject() As ITrackingCallback
Set CallBackObject = m_CallBack
End Property
Public Property Set CallBackObject(theObject As ITrackingCallback)
Set m_CallBack = theObject
End Property
Public Property Get Mode() As eTrackingModes
Mode = m_Mode
End Property
Public Property Let Mode(newMode As eTrackingModes)
m_Mode = newMode
End Property
Private Sub Class_Terminate()
Set m_CallBack = Nothing
Set theHandle = Nothing
End Sub
Private Sub theHandle_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
m_isActive = False
If GetCapture = theHandle.hwnd Then ReleaseCapture