2011-01-20 2 views
1

J'ai besoin de contrôler le volume de l'ordinateur principal dans vb.net. J'ai cherché sur le web et essayé tous les exemples que j'ai pu trouver. Aucun des ont travaillé.Volume de contrôle dans vb.net

Quelqu'un a-t-il des extraits de code qui fonctionnent avec vb.net 2010 pour contrôler le volume?

Merci
giodamelio

Répondre

2

Je trouve une réponse. Ses utilisations Nirsoft de NirCmd (32-bit, 64-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 

Vous pouvez ensuite utiliser somthing comme

Dim vol As New Sound(path_to_nircmd) 
vol.setVol(50) 
0

Je sais que cette question est vraiment vieux, mais cela a fonctionné pour moi:

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