vb.net中的控制卷

时间:2011-01-20 21:48:06

标签: vb.net volume

我需要控制vb.net中的主计算机卷。我在网上搜索并尝试了我能找到的所有例子。没有一个有效。

有没有人有一些与vb.net 2010一起使用的代码片段来控制音量?

感谢
giodamelio

3 个答案:

答案 0 :(得分:2)

我找到了答案。它使用 Nirsoft的NirCmd 32-bit64-bit

Public Class Sound
    Dim nircmd As String
    Const MAXVOL As Integer = 65535

    Public Sub New(ByVal nircmd_location As String)
        nircmd = nircmd_location
    End Sub

    Public Sub setVol(ByVal level As Integer)

        Dim p As New ProcessStartInfo
        p.FileName = nircmd
        p.Arguments = "setsysvolume " & (MAXVOL * (level / 100)).ToString
        Process.Start(p)

    End Sub
End Class

然后你可以使用像

这样的东西
Dim vol As New Sound(path_to_nircmd)
vol.setVol(50)

答案 1 :(得分:1)

我知道这个问题真的很老了,但这对我很有用:

http://www.dotnetcurry.com/showarticle.aspx?ID=431

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Namespace WindowsFormsApplication1
    Partial Public Class Form1
        Inherits 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
End Namespace

答案 2 :(得分:0)