home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch08 / playwave / playwave.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-20  |  2.6 KB  |  80 lines

  1. VERSION 5.00
  2. Begin VB.Form PlayWave2 
  3.    Caption         =   "PlayWave 2"
  4.    ClientHeight    =   2055
  5.    ClientLeft      =   60
  6.    ClientTop       =   330
  7.    ClientWidth     =   3000
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2055
  10.    ScaleWidth      =   3000
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Sound 
  13.       Caption         =   "Play"
  14.       Height          =   1335
  15.       Left            =   360
  16.       TabIndex        =   0
  17.       Top             =   240
  18.       Width           =   2055
  19.    End
  20. Attribute VB_Name = "PlayWave2"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26.     Private Declare Function mciSendCommandA Lib "WinMM" _
  27.         (ByVal wDeviceID As Long, ByVal Message As Long, _
  28.         ByVal dwParam1 As Long, dwParam2 As Any) As Long
  29.     Const MCI_OPEN = &H803
  30.     Const MCI_CLOSE = &H804
  31.     Const MCI_PLAY = &H806
  32.     Const MCI_OPEN_TYPE = &H2000&
  33.     Const MCI_OPEN_ELEMENT = &H200&
  34.     Const MCI_WAIT = &H2&
  35.     Private Type MCI_WAVE_OPEN_PARMS
  36.         dwCallback As Long
  37.         wDeviceID As Long
  38.         lpstrDeviceType As String
  39.         lpstrElementName As String
  40.         lpstrAlias As String
  41.         dwBufferSeconds As Long
  42.     End Type
  43.     Private Type MCI_PLAY_PARMS
  44.         dwCallback As Long
  45.         dwFrom As Long
  46.         dwTo As Long
  47.     End Type
  48. Sub PlayWave(WaveFile As String)
  49.     Dim errorCode As Integer
  50.     Dim returnStr As Integer
  51.     Dim errorStr As String * 256
  52.     Dim MCIWaveOpenParms As MCI_WAVE_OPEN_PARMS
  53.     Dim MCIPlayParms As MCI_PLAY_PARMS
  54.     MCIWaveOpenParms.dwCallback = 0
  55.     MCIWaveOpenParms.wDeviceID = 0
  56.         
  57.     MCIWaveOpenParms.lpstrDeviceType = "waveaudio"
  58.     MCIWaveOpenParms.lpstrElementName = WaveFile
  59.     MCIWaveOpenParms.lpstrAlias = 0
  60.     MCIWaveOpenParms.dwBufferSeconds = 0
  61.     errorCode = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_ELEMENT, _
  62.                                 MCIWaveOpenParms)
  63.     If errorCode = 0 Then
  64.         MCIPlayParms.dwCallback = 0
  65.         MCIPlayParms.dwFrom = 0
  66.         MCIPlayParms.dwTo = 0
  67.         errorCode = mciSendCommandA(MCIWaveOpenParms.wDeviceID, MCI_PLAY, _
  68.                                     MCI_WAIT, MCIPlayParms)
  69.                                 
  70.         errorCode = mciSendCommandA(MCIWaveOpenParms.wDeviceID, MCI_CLOSE, _
  71.                                     0, 0)
  72.     End If
  73. End Sub
  74.         
  75. Private Sub Sound_Click()
  76.     PlayWave App.Path & "\howareu.wav"
  77.         
  78. End Sub
  79.         
  80.