home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch17code / frmcntrl.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-13  |  4.2 KB  |  135 lines

  1. VERSION 4.00
  2. Begin VB.Form frmControlPanel 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "CD Player"
  5.    ClientHeight    =   1128
  6.    ClientLeft      =   1092
  7.    ClientTop       =   1512
  8.    ClientWidth     =   2928
  9.    Height          =   1452
  10.    Left            =   1044
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   1128
  13.    ScaleWidth      =   2928
  14.    Top             =   1236
  15.    Width           =   3024
  16.    Begin MCI.MMControl mciControl 
  17.       Height          =   735
  18.       Left            =   0
  19.       TabIndex        =   0
  20.       Top             =   0
  21.       Width           =   2940
  22.       _Version        =   65536
  23.       StepVisible     =   0   'False
  24.       RecordVisible   =   0   'False
  25.       DeviceType      =   "CDAudio"
  26.       _ExtentX        =   5186
  27.       _ExtentY        =   1291
  28.       _StockProps     =   32
  29.       BorderStyle     =   1
  30.    End
  31. Attribute VB_Name = "frmControlPanel"
  32. Attribute VB_Creatable = False
  33. Attribute VB_Exposed = False
  34. '   Controls the form and MCI control.
  35. '   This is the internal representation of a CD
  36. '   within the applications (exposed as as Title
  37. '   and Tracks outside of the application).
  38. Option Explicit
  39. ' Internal CurrentTitle property
  40. ' (Read/write)
  41. Public CurrentTitle As String
  42. Public Property Get Position() As Long
  43.     Position = Me.mciControl.Position
  44. End Property
  45. Public Property Get ElapsedMinutes() As Integer
  46.     ElapsedMinutes = LoByte(LoWord(Me.Position))
  47. End Property
  48. Public Property Get ElapsedSeconds() As Integer
  49.     ElapsedSeconds = HiByte(LoWord(Me.Position))
  50. End Property
  51. Public Property Get CurrentTrack()
  52.     ' This doesn't work -- bug in control?
  53.     ' CurrentTrack = HiByte(HiWord(Me.Position))
  54.     ' Alternate -- works?
  55.     Dim Index As Integer
  56.     Dim lTrackBegin As Long
  57.     Dim lTrackEnd As Long
  58.     Dim lCurrentPosition As Long
  59.     lCurrentPosition = Me.Position
  60.     For Index = 1 To Me.Tracks
  61.         Me.Track = Index
  62.         lTrackBegin = Me.TrackPosition
  63.         lTrackEnd = lTrackBegin + Me.TrackLength
  64.         If (lTrackBegin < lCurrentPosition) And (lCurrentPosition < lTrackEnd) Then
  65.             CurrentTrack = Index
  66.             Exit Property
  67.         End If
  68.     Next Index
  69. End Property
  70. Public Property Get Tracks() As Integer
  71.     Tracks = Me.mciControl.Tracks
  72. End Property
  73. Public Property Get Track() As Integer
  74.     Track = Me.mciControl.Track
  75. End Property
  76. Public Property Let Track(iSetting As Integer)
  77.     Me.mciControl.Track = iSetting
  78. End Property
  79. Public Property Get TrackPosition() As Long
  80.     TrackPosition = Me.mciControl.TrackPosition
  81. End Property
  82. Public Property Get TrackLength() As Long
  83.     TrackLength = Me.mciControl.TrackLength
  84. End Property
  85. Public Property Let Command(strSetting As String)
  86.     Me.mciControl.Command = strSetting
  87. End Property
  88. Public Sub Play()
  89.     Me.mciControl.Command = "Open"
  90.     Me.mciControl.Command = "Play"
  91. End Sub
  92. Public Sub Eject()
  93.     Me.mciControl.Command = "Eject"
  94. End Sub
  95. Public Sub NextTrack()
  96.     Me.mciControl.Notify = False
  97.     Me.mciControl.Wait = True
  98.     Me.mciControl.Command = "Next"
  99. End Sub
  100. Public Sub PreviousTrack()
  101.     Me.mciControl.Notify = False
  102.     Me.mciControl.Wait = True
  103.     Me.mciControl.Command = "Prev"
  104.     Me.mciControl.Command = "Prev"
  105. End Sub
  106. Private Function LoWord(lVal As Long) As Integer
  107.     If lVal And &HFFFF0000 Then
  108.         LoWord = lVal Mod (lVal And &HFFFF0000)
  109.     Else
  110.         LoWord = lVal
  111.     End If
  112. End Function
  113. Private Function HiWord(lVal As Long) As Integer
  114.         HiWord = (lVal And &HFFFF0000) \ &H10000
  115. End Function
  116. Private Function HiByte(iVal As Integer) As Byte
  117.         HiByte = (iVal And &HFF00) \ &H100
  118. End Function
  119. Private Function LoByte(iVal As Integer) As Byte
  120.     If iVal And &HFF00 Then
  121.         LoByte = iVal Mod (iVal And &HFF00)
  122.     Else
  123.         LoByte = iVal
  124.     End If
  125. End Function
  126. Private Sub Form_Load()
  127.     Me.mciControl.AutoEnable = True
  128.     Me.mciControl.TimeFormat = mciFormatTmsf
  129. End Sub
  130. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  131.     Set Application = Nothing
  132. End Sub
  133. Private Sub mciControl_Done(NotifyCode As Integer)
  134. End Sub
  135.