Imports System.Runtime.InteropServices
Public Class Form1
Private mute As Integer = &H80000
Private up As Integer = &HA0000
Private down As Integer = &H90000
Private WM_APPCOMMAND As Integer = &H319
<DllImport("user32.dll")> _
Public Shared Function SendMessageW(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
End Function
‘按滑动条实时调整系统主音量
’应该有更精准的控制音量的方法,但目前我查到的资料中是使用大篇幅的API,太复杂了。
‘本方法虽然不太精准,但胜在语句简单
'trackBarVolumn.Value最大值需设置为100,最小值设置为0;如果不同,调整相应参数
Select Case trackBaVolumn.Value
Case 0 '静音
SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, New IntPtr(mute))
Case 100‘最大音量
For intI As Integer = 1 To 50
SendMessageW(Me.Handle, WM_APPCOMMAND, True, New IntPtr(up))
Next
Case Else '调整到滑动条位置
'调整到最大系统音量
For intI As Integer = 1 To 50
SendMessageW(Me.Handle, WM_APPCOMMAND, True, New IntPtr(up))
Next
‘降低到相应音量
For intJ As Integer = 1 To 50 - (trackBarVolumn.Value \ 2)
SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, New IntPtr(down))
Next
End Select
End Class
Imports System.Runtime.InteropServicesPublic Class Form1Private mute As Integer = &H80000Private up As Integer = &HA0000Private down As Integer = &H90000Private WM_APPCOMMAND As Integer = &H319<DllImport("user32.dll")> _Public