www.pudn.com > gdqj1a302.zip > MCI.bas


Attribute VB_Name = "mdMCI" 
'******************************************************************************* 
' MCI.bas  ¶àýÌåÄ£¿é 
'******************************************************************************* 
 
Const MCI_OPEN = &H803 
Const MCI_CLOSE = &H804 
Const MCI_PLAY = &H806 
Const MCI_OPEN_ELEMENT = &H200& 
Const MCI_OPEN_ALIAS = &H400& 
Const MCI_WAIT = &H2& 
Private Declare Function mciSendCommandA Lib "WinMM" (ByVal DeviceId As Integer, ByVal Message As Integer, ByVal Param1 As Long, Param2 As Any) As Long 
Private Declare Function mciGetErrorStringA Lib "WinMM" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal wLength As Integer) As Integer 
Private Declare Function lstrcatA Lib "Kernel32" (Str1 As Any, ByVal str2 As Any) As Long 
 
Type MCI_OPEN_PARMS 
    dwCallback As Long 
    wDeviceid As Integer 
    wReserved0 As Integer 
    lpstrDeviceType As Long 
    lpstrElementName As Long 
    lpstrAlias As Long 
End Type 
Type MCI_PLAY_PARMS 
    dwCallback As Long 
    dwFrom As Long 
    dwTo As Long 
End Type 
Type MCI_GENERIC_PARMS 
    dwCallback As Long 
End Type 
Type stringX 
    Str As String * 256 
End Type 
 
 
Public Function SoundWave(FileName$, nRepeat%) 
    Dim mciOpen As MCI_OPEN_PARMS 
    Dim mciPlay As MCI_PLAY_PARMS 
    Dim mciGeneric As MCI_GENERIC_PARMS 
    Dim ElementName As stringX 
    Dim aliasName As stringX 
    Dim ReturnCode As Integer 
    Dim ErrorCode As Long 
    Dim NullString As String * 1 
     
    mciOpen.dwCallback = 0& 
    mciOpen.wDeviceid = 0 
    mciOpen.wReserved0 = 0 
     
    ElementName.Str = FileName$ & Chr$(0) 
    aliasName.Str = "wave" & Chr$(0) 
    mciOpen.lpstrDeviceType = 0& 
    NullString = Chr$(0) 
     
    For i% = 1 To nRepeat% 
        mciOpen.lpstrElementName = lstrcatA(ElementName, NullString) 
        mciOpen.lpstrAlias = lstrcatA(aliasName, NullString) 
        ErrorCode = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_ELEMENT Or MCI_OPEN_ALLAS, mciOpen) 
 
        If ErrorCode = 0 Then 
            DeviceId = mciOpen.wDeviceid 
            mciPlay.dwCallback = 0& 
            mciPlay.dwFrom = 0& 
            mciPlay.dwTo = 0& 
            mciGeneric.dwCallback = 0& 
     
            ErrorCode = mciSendCommandA(DeviceId, MCI_PLAY, MCI_WAIT, mciPlay) 
            ErrorCode = mciSendCommandA(DeviceId, MCI_CLOSE, MCI_WAIT, mciGeneric) 
        End If 
    Next i% 
 
End Function