vb.netalias的简单介绍( 四 )


' Declare a variable to hold the return value from mciSendString
Dim nReturn As Long
' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub
nReturn = mciSendString("Stop "sAlias, "", 0, 0)
End Sub
Public Sub mmSeek(ByVal nPosition As Single)
' Seeks to a specific position within the file
' Declare a variable to hold the return value from the mciSendString
' function
Dim nReturn As Long
nReturn = mciSendString("Seek "sAlias" to "nPosition, "", 0, 0)
End Sub
Property Get Filename() As String
' Routine to return a value when the programmer asks the
' object for the value of its Filename property
Filename = sFilename
End Property
Property Let Filename(ByVal sTheFile As String)
' Routine to set the value of the filename property, should the programmer
' wish to do so. This implies that the programmer actually wants to open
' a file as well so control is passed to the mmOpen routine
mmOpen sTheFile
End Property
Property Get Wait() As Boolean
' Routine to return the value of the object's wait property.
Wait = bWait
End Property
Property Let Wait(bWaitValue As Boolean)
' Routine to set the value of the object's wait property
bWait = bWaitValue
End Property
Property Get Length() As Single
' Routine to return the length of the currently opened multimedia file
' Declare a variable to hold the return value from the mciSendString
Dim nReturn As Long, nLength As Integer
' Declare a string to hold the returned length from the mci Status call
Dim sLength As String * 255
' If there is no file open then return 0
If sAlias = "" Then
Length = 0
Exit Property
End If
nReturn = mciSendString("Status "sAlias" length", sLength, 255, 0)
nLength = InStr(sLength, Chr$(0))
Length = Val(Left$(sLength, nLength - 1))
End Property
Property Let Position(ByVal nPosition As Single)
' Sets the Position property effectively by seeking
mmSeek nPosition
End Property
Property Get Position() As Single
' Returns the current position in the file
' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer
' Declare a variable to hold the position returned
' by the mci Status position command
Dim sPosition As String * 255
' If there is no file currently opened then exit the subroutine
If sAlias = "" Then Exit Property
' Get the position and return
nReturn = mciSendString("Status "sAlias" position", sPosition, 255, 0)
nLength = InStr(sPosition, Chr$(0))
Position = Val(Left$(sPosition, nLength - 1))
End Property
Property Get Status() As String
' Returns the playback/record status of the current file
' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer
' Declare a variable to hold the return string from mciSendString
Dim sStatus As String * 255
' If there is no file currently opened, then exit the subroutine
If sAlias = "" Then Exit Property
nReturn = mciSendString("Status "sAlias" mode", sStatus, 255, 0)
nLength = InStr(sStatus, Chr$(0))
Status = Left$(sStatus, nLength - 1)
End Property
//窗体fm
Dim m As New Mmedia
Dim fn
Private Sub Command1_Click()
On Error GoTo r
dlg.ShowOpen
fn = dlg.Filename
m.mmOpen fn
r:
If Err Then MsgBox Err.Description
End Sub
Private Sub Command2_Click()
On Error GoTo rp
m.mmPlay
rp:
If Err Then MsgBox Err.Description
End Sub
Private Sub Command3_Click()
On Error GoTo rap
m.mmPause
rap:
If Err Then MsgBox Err.Description
End Sub

推荐阅读