'在窗体内建立一个command1控件,复制下面代码,运行后按command1按钮一次声音关,第二次声音开,第三次又关。。。
'=======代码部分=======
'Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
keybd_event 173, 0, 0, 0
End Sub
如果是编写播放器的话就用 mciSendString 函数。有个命令 set volume on 。你可以查一下 MSDN。有很详细的参数。
v
Option Explicit
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_APPCOMMAND As Long = &H319
Private Const APPCOMMAND_VOLUME_MUTE As Long = 8
Private Sub Command1_Click()
'静音,单击一次静音,再单击一次恢复
SendMessage Me.hwnd, WM_APPCOMMAND, &H200EB0, APPCOMMAND_VOLUME_MUTE * &H10000
End Sub