Imports System.IO Public Class Form1 ' winmm.Dllの利用 Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer ' 現在の音量 Private iVol As Integer = 1000 '開始 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' 音楽ファイルのパスを指定 Dim strFileName As String = "音楽ファイルのパス" Call mciSendString(String.Format("open ""{0}"" alias MySound", strFileName), "", 0, 0) Call mciSendString("play MySound", "", 0, 0) End Sub '停止 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Call mciSendString("stop MySound", "", 0, 0) Call mciSendString("close MySound", "", 0, 0) End Sub 'ボリュームを下げる Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.volumeChange(-100) End Sub 'ボリュームを上げる。 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.volumeChange(100) End Sub ''' <summary> ''' ボリュームを調整する ''' </summary> ''' <param name="iVol">調整するボリューム</param> Private Sub volumeChange(ByVal iVol As Integer) Const INT_VOLUME_MIN As Integer = 0 '音量の最小値 Const INT_VOLUME_MAX As Integer = 1000 ' 〃 最大値 ' コマンド Dim strCommand As String = String.Empty Me.iVol += iVol ' 閾値(最小と最大)の確認 If (Me.iVol < INT_VOLUME_MIN) Then Me.iVol = INT_VOLUME_MIN ElseIf (Me.iVol > INT_VOLUME_MAX) Then Me.iVol = INT_VOLUME_MAX End If strCommand = String.Concat("setaudio MySound Volume to ", Me.iVol.ToString()) Console.WriteLine("volumeChange:" + Me.iVol.ToString()) Call mciSendString(strCommand, "", 0, 0) End Sub End Class