📄 form1.vb
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
Public Sub New()
MyBase.New()
If m_vb6FormDefInstance Is Nothing Then
If m_InitializingDefInstance Then
m_vb6FormDefInstance = Me
Else
Try
'对于启动窗体,所创建的第一个实例为默认实例。
If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
m_vb6FormDefInstance = Me
End If
Catch
End Try
End If
End If
'此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
End Sub
'窗体重写处置,以清理组件列表。
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
Private components As System.ComponentModel.IContainer
'Windows 窗体设计器所必需的
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents Command2 As System.Windows.Forms.Button
Public WithEvents Command1 As System.Windows.Forms.Button
Public WithEvents HScroll2 As System.Windows.Forms.HScrollBar
Public WithEvents HScroll1 As System.Windows.Forms.HScrollBar
Public WithEvents Label2 As System.Windows.Forms.Label
Public WithEvents Label1 As System.Windows.Forms.Label
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器来修改它。
'不要使用代码编辑器来修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.Command1 = New System.Windows.Forms.Button()
Me.Command2 = New System.Windows.Forms.Button()
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.HScroll2 = New System.Windows.Forms.HScrollBar()
Me.HScroll1 = New System.Windows.Forms.HScrollBar()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Command1
'
Me.Command1.BackColor = System.Drawing.SystemColors.Control
Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
Me.Command1.Location = New System.Drawing.Point(8, 83)
Me.Command1.Name = "Command1"
Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command1.Size = New System.Drawing.Size(166, 29)
Me.Command1.TabIndex = 4
Me.Command1.Text = "停止播放"
'
'Command2
'
Me.Command2.BackColor = System.Drawing.SystemColors.Control
Me.Command2.Cursor = System.Windows.Forms.Cursors.Default
Me.Command2.Location = New System.Drawing.Point(192, 83)
Me.Command2.Name = "Command2"
Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command2.Size = New System.Drawing.Size(175, 29)
Me.Command2.TabIndex = 5
Me.Command2.Text = "播放测试声音"
'
'HScroll2
'
Me.HScroll2.Cursor = System.Windows.Forms.Cursors.Default
Me.HScroll2.LargeChange = 1
Me.HScroll2.Location = New System.Drawing.Point(80, 46)
Me.HScroll2.Maximum = 255
Me.HScroll2.Name = "HScroll2"
Me.HScroll2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.HScroll2.Size = New System.Drawing.Size(288, 20)
Me.HScroll2.TabIndex = 2
Me.HScroll2.TabStop = True
'
'HScroll1
'
Me.HScroll1.Cursor = System.Windows.Forms.Cursors.Default
Me.HScroll1.LargeChange = 1
Me.HScroll1.Location = New System.Drawing.Point(80, 19)
Me.HScroll1.Maximum = 255
Me.HScroll1.Name = "HScroll1"
Me.HScroll1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.HScroll1.Size = New System.Drawing.Size(288, 19)
Me.HScroll1.TabIndex = 0
Me.HScroll1.TabStop = True
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(8, 19)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(63, 19)
Me.Label1.TabIndex = 1
Me.Label1.Text = "左声道"
'
'Label2
'
Me.Label2.BackColor = System.Drawing.SystemColors.Control
Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label2.Location = New System.Drawing.Point(8, 46)
Me.Label2.Name = "Label2"
Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label2.Size = New System.Drawing.Size(63, 20)
Me.Label2.TabIndex = 3
Me.Label2.Text = "右声道"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(376, 119)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Command2, Me.Command1, Me.HScroll2, Me.HScroll1, Me.Label2, Me.Label1})
Me.Location = New System.Drawing.Point(3, 16)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "控制音量API函数的使用"
Me.ResumeLayout(False)
End Sub
#End Region
#Region "升级支持"
Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As Form1
Get
If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New Form1()
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set
m_vb6FormDefInstance = Value
End Set
End Property
#End Region
Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByRef lpdwVolume As Integer) As Integer
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByVal dwVolume As Integer) As Integer
Private Declare Function waveOutGetDevCaps Lib "winmm.dll" Alias "waveOutGetDevCapsA"(ByVal uDeviceID As Integer, ByRef lpCaps As WAVEOUTCAPS, ByVal uSize As Integer) As Integer
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA"(ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer
Const SND_ASYNC As Short = &H1s
Const SND_PURGE As Short = &H40s
Const WAVE_MAPPER As Short = -1
Const MAXPNAMELEN As Short = 32
Const MMSYSERR_NOERROR As Short = 0
Private Structure WAVEOUTCAPS
Dim wMid As Short
Dim wPid As Short
Dim vDriverVersion As Integer
<VBFixedString(MAXPNAMELEN),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=MAXPNAMELEN)> Dim szPname As String
Dim dwFormats As Integer
Dim wChannels As Short
Dim dwSupport As Integer
End Structure
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim lVol As Integer
Dim tWaveCaps As WAVEOUTCAPS
waveOutGetVolume(WAVE_MAPPER, lVol)
System.Diagnostics.Debug.WriteLine(Hex(lVol))
HScroll1.Value = (lVol And 255)
HScroll2.Value = ((lVol \ &H10000) And 255)
End Sub
Private Sub HScroll1_Change(ByVal newScrollValue As Integer)
SetVolume()
End Sub
Private Sub HScroll2_Change(ByVal newScrollValue As Integer)
SetVolume()
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
'停止播放测试声音
Dim aa As String
sndPlaySound(aa, SND_ASYNC)
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
'播放播放测试声音
sndPlaySound("e:\demo1.wav", SND_ASYNC)
End Sub
Sub SetVolume()
Dim lVol As Integer
lVol = CInt(HScroll2.Value) * &H100S Or HScroll1.Value
'设置音量
If waveOutSetVolume(WAVE_MAPPER, lVol) <> MMSYSERR_NOERROR Then
MsgBox("音量设置出错")
End If
End Sub
Private Sub HScroll1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles HScroll1.Scroll
Select Case eventArgs.Type
Case System.Windows.Forms.ScrollEventType.EndScroll
HScroll1_Change(eventArgs.NewValue)
End Select
End Sub
Private Sub HScroll2_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles HScroll2.Scroll
Select Case eventArgs.Type
Case System.Windows.Forms.ScrollEventType.EndScroll
HScroll2_Change(eventArgs.NewValue)
End Select
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -