是否可以使用 VB.NET 中的轨迹栏控件来控制系统音量?
当用户调整 trackbar 的值时,系统的音量也会发生变化。
提前致谢!
我在@dude 提供的链接上找到了答案。谢谢。
导入系统导入 System.Windows.Forms 导入 System.Runtime.InteropServices
命名空间 WindowsFormsApplication1 部分公共类 Form1 继承 Form Private Const APPCOMMAND_VOLUME_MUTE As Integer = &H80000 Private Const APPCOMMAND_VOLUME_UP As Integer = &HA0000 Private Const APPCOMMAND_VOLUME_DOWN As Integer = &H90000 Private Const WM_APPCOMMAND As Integer = &H319
<DllImport("user32.dll")> _
Public Shared Function SendMessageW(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
End Function
Private Sub btnMute_Click(ByVal sender As Object, ByVal e As EventArgs)
SendMessageW(Me.Handle, WM_APPCOMMAND, _
Me.Handle, New IntPtr(APPCOMMAND_VOLUME_MUTE))
End Sub
Private Sub btnDecVol_Click(ByVal sender As Object, ByVal e As EventArgs)
SendMessageW(Me.Handle, WM_APPCOMMAND, _
Me.Handle, New IntPtr(APPCOMMAND_VOLUME_DOWN))
End Sub
Private Sub btnIncVol_Click(ByVal sender As Object, ByVal e As EventArgs)
SendMessageW(Me.Handle, WM_APPCOMMAND, _
Me.Handle, New IntPtr(APPCOMMAND_VOLUME_UP))
End Sub
End Class
结束命名空间