调整Windows扬声器音量VB.NET

时间:2011-05-23 13:12:37

标签: windows vb.net volume

如何通过VB.NET更改Windows扬声器音量(主输出音量控制音量值)?我希望有一种方法可以像在Windows 7上的音量控制应用程序中那样间接地改变整个系统的音量

1 个答案:

答案 0 :(得分:2)

自:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/8308f020-b9e6-472c-aaac-93619a8a5a7d/vbnet-control-the-system-volume-mute-and-output-the-current-level-to-the-user?forum=vbgeneral

Imports System.Runtime.InteropServices
Public Class Form1
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function

    Const WM_APPCOMMAND As UInteger = &H319
    Const APPCOMMAND_VOLUME_UP As UInteger = &HA
    Const APPCOMMAND_VOLUME_DOWN As UInteger = &H9
    Const APPCOMMAND_VOLUME_MUTE As UInteger = &H8

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_UP * &H10000)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_DOWN * &H10000)
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SendMessage(Me.Handle, WM_APPCOMMAND, &H200EB0, APPCOMMAND_VOLUME_MUTE * &H10000)
    End Sub
End Class

我能够在一分钟内把它扔到一起没问题。