home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / weelactx / wheel.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-09-25  |  10.0 KB  |  296 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Wheel 
  3.    ClientHeight    =   2160
  4.    ClientLeft      =   0
  5.    ClientTop       =   0
  6.    ClientWidth     =   1035
  7.    ScaleHeight     =   2160
  8.    ScaleWidth      =   1035
  9.    ToolboxBitmap   =   "Wheel.ctx":0000
  10.    Begin VB.Image Image1 
  11.       Height          =   1650
  12.       Left            =   0
  13.       Picture         =   "Wheel.ctx":00FA
  14.       Top             =   0
  15.       Width           =   180
  16.    End
  17. Attribute VB_Name = "Wheel"
  18. Attribute VB_GlobalNameSpace = False
  19. Attribute VB_Creatable = True
  20. Attribute VB_PredeclaredId = False
  21. Attribute VB_Exposed = True
  22. Option Explicit
  23. 'Default Property Values:
  24. Const m_def_Enabled = True
  25. Const m_def_Style = 0
  26. Const LIMIT = 1650
  27. Const LO_LIMIT = LIMIT / 2 - 50
  28. Const HI_LIMIT = LIMIT / 2 + 50
  29. 'Property Variables:
  30. Dim m_Enabled As Boolean
  31. Dim m_Style As Integer
  32. 'Event Declarations:
  33. Event Wheel(Direction As Direction)
  34. Public Enum Direction
  35.     wheelUp = 0
  36.     wheelDown
  37.     wheelLeft
  38.     wheelRight
  39. End Enum
  40. Public Enum WheelStyle
  41.     wheelVertical = 0
  42.     wheelHorizontal
  43. End Enum
  44. Private Counter As Integer
  45. Private currY As Single
  46. Private currX As Single
  47. Private bCancel As Boolean
  48. Private lDelay As Long
  49. Private iDirection As Single
  50. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  51. Public Property Get Enabled() As Boolean
  52. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  53.     Enabled = m_Enabled
  54. End Property
  55. Private Function GetResPic() As IPictureDisp
  56.     If m_Style = wheelVertical Then
  57.         Select Case Counter
  58.             Case 0
  59.                 Set GetResPic = LoadResPicture(101, vbResBitmap)
  60.             Case 1
  61.                 Set GetResPic = LoadResPicture(102, vbResBitmap)
  62.             Case 2
  63.                 Set GetResPic = LoadResPicture(103, vbResBitmap)
  64.             Case 3
  65.                 Set GetResPic = LoadResPicture(104, vbResBitmap)
  66.         End Select
  67.     Else
  68.         Select Case Counter
  69.             Case 0
  70.                 Set GetResPic = LoadResPicture(105, vbResBitmap)
  71.             Case 1
  72.                 Set GetResPic = LoadResPicture(106, vbResBitmap)
  73.             Case 2
  74.                 Set GetResPic = LoadResPicture(107, vbResBitmap)
  75.             Case 3
  76.                 Set GetResPic = LoadResPicture(108, vbResBitmap)
  77.         End Select
  78.     End If
  79. End Function
  80. Public Property Get WheelStyle() As WheelStyle
  81.     WheelStyle = m_Style
  82. End Property
  83. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  84.     m_Enabled = New_Enabled
  85.     PropertyChanged "Enabled"
  86. End Property
  87. Public Property Let WheelStyle(ByVal New_Style As WheelStyle)
  88.     m_Style = New_Style
  89.     UserControl_Resize
  90. End Property
  91. Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  92.     If m_Enabled Then
  93.         If Button = vbLeftButton Then
  94.             currY = Y
  95.             currX = X
  96.         End If
  97.         
  98.         
  99.         '*********
  100.         If Button = vbRightButton Then
  101.             If m_Style = wheelVertical Then
  102.                 If Y < LO_LIMIT Then
  103.                     iDirection = 1
  104.                     bCancel = False
  105.                     lDelay = 3 * Y / Screen.TwipsPerPixelY
  106.                 ElseIf Y > HI_LIMIT Then
  107.                     iDirection = -1
  108.                     bCancel = False
  109.                     lDelay = 3 * (LIMIT - Y) / Screen.TwipsPerPixelY
  110.                 End If
  111.                 
  112.                 Do Until bCancel
  113.                           
  114.                         Counter = Counter + iDirection
  115.                         
  116.                         If Counter > 3 Then
  117.                             Counter = 0
  118.                         End If
  119.                         
  120.                         If Counter < 0 Then
  121.                             Counter = 3
  122.                         End If
  123.                         
  124.                         
  125.                         Image1.Picture = GetResPic()
  126.                         If iDirection = 1 Then
  127.                             RaiseEvent Wheel(wheelUp)
  128.                         ElseIf iDirection = -1 Then
  129.                             RaiseEvent Wheel(wheelDown)
  130.                         End If
  131.                         
  132.                         DoEvents
  133.                         Sleep lDelay
  134.                 Loop
  135.                 
  136.             ElseIf m_Style = wheelHorizontal Then
  137.                 If X < LO_LIMIT Then
  138.                     iDirection = -1
  139.                     bCancel = False
  140.                     lDelay = 3 * X / Screen.TwipsPerPixelX
  141.                 ElseIf X > HI_LIMIT Then
  142.                     iDirection = 1
  143.                     bCancel = False
  144.                     lDelay = 3 * (LIMIT - X) / Screen.TwipsPerPixelX
  145.                 End If
  146.                 
  147.                 Do Until bCancel
  148.                         
  149.                           
  150.                         Counter = Counter + iDirection
  151.                         
  152.                         If Counter > 3 Then
  153.                             Counter = 0
  154.                         End If
  155.                         
  156.                         If Counter < 0 Then
  157.                             Counter = 3
  158.                         End If
  159.                         
  160.                         
  161.                         Image1.Picture = GetResPic()
  162.                         If iDirection = 1 Then
  163.                             RaiseEvent Wheel(wheelRight)
  164.                         ElseIf iDirection = -1 Then
  165.                             RaiseEvent Wheel(wheelLeft)
  166.                         End If
  167.                         
  168.                         DoEvents
  169.                         Sleep lDelay
  170.                 Loop
  171.                 
  172.             End If
  173.         End If
  174.         
  175.         
  176.         
  177.         
  178.         
  179.     End If
  180. End Sub
  181. Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  182.     If m_Enabled Then
  183.         If Button = vbLeftButton Then
  184.             If m_Style = wheelVertical Then
  185.                 If Y < currY Then
  186.                     currY = Y
  187.                     Counter = Counter + 1
  188.                     If Counter > 3 Then
  189.                         Counter = 0
  190.                     End If
  191.                     Image1.Picture = GetResPic()
  192.                     RaiseEvent Wheel(wheelUp)
  193.                 ElseIf Y > currY Then
  194.                     currY = Y
  195.                     Counter = Counter - 1
  196.                     If Counter < 0 Then
  197.                         Counter = 3
  198.                     End If
  199.                     Image1.Picture = GetResPic()
  200.                     RaiseEvent Wheel(wheelDown)
  201.                 End If
  202.             Else
  203.                 If X > currX Then
  204.                     currX = X
  205.                     Counter = Counter + 1
  206.                     If Counter > 3 Then
  207.                         Counter = 0
  208.                     End If
  209.                     Image1.Picture = GetResPic()
  210.                     RaiseEvent Wheel(wheelRight)
  211.                 ElseIf X < currX Then
  212.                     currX = X
  213.                     Counter = Counter - 1
  214.                     If Counter < 0 Then
  215.                         Counter = 3
  216.                     End If
  217.                     Image1.Picture = GetResPic()
  218.                     RaiseEvent Wheel(wheelLeft)
  219.                 End If
  220.             End If
  221.         End If
  222.         
  223.         'Continous scroll
  224.         If Button = vbRightButton Then
  225.             If m_Style = wheelVertical Then
  226.                 If Y < LO_LIMIT Then
  227.                     lDelay = 3 * Y / Screen.TwipsPerPixelY
  228.                     iDirection = 1
  229.                 ElseIf Y > HI_LIMIT Then
  230.                     lDelay = 3 * (LIMIT - Y) / Screen.TwipsPerPixelY
  231.                     iDirection = -1
  232.                 Else
  233.                     iDirection = 0
  234.                 End If
  235.             ElseIf m_Style = wheelHorizontal Then
  236.                 If X < LO_LIMIT Then
  237.                     lDelay = 3 * X / Screen.TwipsPerPixelX
  238.                     iDirection = -1
  239.                 ElseIf X > HI_LIMIT Then
  240.                     lDelay = 3 * (LIMIT - X) / Screen.TwipsPerPixelX
  241.                     iDirection = 1
  242.                 Else
  243.                     iDirection = 0
  244.                 End If
  245.             End If
  246.             
  247.             If lDelay < 5 Then
  248.                 lDelay = 5
  249.             End If
  250.             
  251.         End If
  252.         
  253.     End If
  254. End Sub
  255. Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  256.     bCancel = True
  257. End Sub
  258. 'Initialize Properties for User Control
  259. Private Sub UserControl_InitProperties()
  260.     m_Enabled = m_def_Enabled
  261.     m_Style = m_def_Style
  262.     Counter = 0
  263.     Image1.Picture = GetResPic()
  264. End Sub
  265. 'Load property values from storage
  266. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  267.     m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
  268.     m_Style = PropBag.ReadProperty("Style", m_def_Style)
  269.     Image1.ToolTipText = PropBag.ReadProperty("ToolTipText", "")
  270. End Sub
  271. Private Sub UserControl_Resize()
  272.     Image1.Picture = GetResPic()
  273.     With UserControl
  274.         .Width = Image1.Width
  275.         .Height = Image1.Height
  276.     End With
  277. End Sub
  278. Private Sub UserControl_Show()
  279.     UserControl_Resize
  280. End Sub
  281. 'Write property values to storage
  282. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  283.     Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  284.     Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
  285.     Call PropBag.WriteProperty("ToolTipText", Image1.ToolTipText, "")
  286. End Sub
  287. Public Sub About()
  288. Attribute About.VB_UserMemId = -552
  289.     MsgBox "Created by Jaroslaw Zwierz" & vbCr & _
  290.         "jerry@ave.com.pl" & vbCr & vbCr & _
  291.         "(c)1997 by AVE Inc." & vbCr & _
  292.         "Poland" & vbCr & vbCr & _
  293.         "This control is a freeware." _
  294.         , vbInformation, "Information"
  295. End Sub
  296.