Public Class Form1
Inherits System.Windows.Forms.Form
' Константы
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004
Private Declare Auto Function PlaySound
Lib "winmm.dll" ( _
ByVal name
As String, _
ByVal hmod
As Integer, _
ByVal flags
As Integer)
As Integer
Private Declare Function waveOutGetNumDevs
Lib "winmm" ()
As Integer
Private Declare Function waveInGetNumDevs
Lib "winmm.dll" ()
As Integer
' Функция для воспроизведения midi
Private Declare Function mciSendString
Lib "winmm.dll" _
Alias "mciSendStringA" _
 
ByVal lpstrCommand
As String, _
ByVal lpstrReturnString
As String, _
ByVal uReturnLength
As Long, _
ByVal hwndCallback
As Long)
As Long
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.
New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected
Overloads Overrides Sub Dispose(
ByVal disposing
As Boolean)
If disposing
Then
If Not (components
Is Nothing)
Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components
As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents butPlay
As System.Windows.Forms.Button
Friend WithEvents butSoundCard
As System.Windows.Forms.Button
Friend WithEvents butIn
As System.Windows.Forms.Button
Friend WithEvents lblInfo
As System.Windows.Forms.Label
Friend WithEvents butMidi
As System.Windows.Forms.Button
Friend WithEvents butCloseMidi
As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.butPlay =
New System.Windows.Forms.Button
Me.butSoundCard =
New System.Windows.Forms.Button
Me.butIn =
New System.Windows.Forms.Button
Me.lblInfo =
New System.Windows.Forms.Label
Me.butMidi =
New System.Windows.Forms.Button
Me.butCloseMidi =
New System.Windows.Forms.Button
Me.SuspendLayout()
'
'butPlay
'
Me.butPlay.Location =
New System.Drawing.Point(8, 56)
Me.butPlay.
Name = "butPlay"
Me.butPlay.Size =
New System.Drawing.Size(144, 32)
Me.butPlay.TabIndex = 0
Me.butPlay.Text = "Воспроизвести звук"
'
'butSoundCard
'
Me.butSoundCard.Location =
New System.Drawing.Point(8, 16)
Me.butSoundCard.
Name = "butSoundCard"
Me.butSoundCard.Size =
New System.Drawing.Size(144, 32)
Me.butSoundCard.TabIndex = 1
Me.butSoundCard.Text = "Проверка звуковой карты"
'
'butIn
'
Me.butIn.Location =
New System.Drawing.Point(8, 96)
Me.butIn.
Name = "butIn"
Me.butIn.Size =
New System.Drawing.Size(144, 32)
Me.butIn.TabIndex = 2
Me.butIn.Text = "Устройства записи"
'
'lblInfo
'
Me.lblInfo.Location =
New System.Drawing.Point(176, 24)
Me.lblInfo.
Name = "lblInfo"
Me.lblInfo.Size =
New System.Drawing.Size(248, 48)
Me.lblInfo.TabIndex = 3
'
'butMidi
'
Me.butMidi.Location =
New System.Drawing.Point(440, 24)
Me.butMidi.
Name = "butMidi"
Me.butMidi.Size =
New System.Drawing.Size(144, 24)
Me.butMidi.TabIndex = 4
Me.butMidi.Text = "MIDI"
'
'butCloseMidi
'
Me.butCloseMidi.Location =
New System.Drawing.Point(440, 72)
Me.butCloseMidi.
Name = "butCloseMidi"
Me.butCloseMidi.Size =
New System.Drawing.Size(144, 24)
Me.butCloseMidi.TabIndex = 5
Me.butCloseMidi.Text = "Закрыть MIDI"
'
'Form1
'
Me.AutoScaleBaseSize =
New System.Drawing.Size(6, 15)
Me.ClientSize =
New System.Drawing.Size(624, 176)
Me.Controls.Add(
Me.butCloseMidi)
Me.Controls.Add(
Me.butMidi)
Me.Controls.Add(
Me.lblInfo)
Me.Controls.Add(
Me.butIn)
Me.Controls.Add(
Me.butSoundCard)
Me.Controls.Add(
Me.butPlay)
Me.
Name = "Form1"
Me.Text = "Воспроизведение"
Me.ResumeLayout(
False)
End Sub
#
End Region
Private Sub butPlay_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles butPlay.Click
PlaySound(Application.StartupPath & "/meow.wav", _
Nothing, SND_FILENAME
Or SND_ASYNC)
End Sub
Private Sub butSoundCard_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles butSoundCard.Click
MsgBox(IsSoundCardPresent)
End Sub
Function IsSoundCardPresent()
As Boolean
Return waveOutGetNumDevs() >= 1
End Function
Private Sub butIn_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles butIn.Click
lblInfo.Text = "Доступно " & waveInGetNumDevs() & " устройства записи"
End Sub
Public Sub butMidi_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles butMidi.Click
Dim lRet
As Long
Dim testmidi
As String = "C:\Windows\Media\town.mid"
' Открываем устройство для проигрывания файла MIDI
lRet = mciSendString( _
"open " & testmidi & " type sequencer alias mplayer", _
0&, 0, 0)
' Начинаем воспроизведение
lRet = mciSendString("play mplayer", 0&, 0, 0)
End Sub
Private Sub butCloseMidi_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles butCloseMidi.Click
' Закрываем файл и устройство
mciSendString("close mplayer", 0&, 0, 0)
End Sub
End Class