Re: Mute volume in vb.net program

From: SStory (TheStorys_at_TAKEOUTTHISSPAMBUSTERsofthome.net)
Date: 02/10/04


Date: Mon, 9 Feb 2004 18:28:50 -0600

Bob, I'm pretty sure it will require an API call....

I wrote a volume control long ago..... It changed the volume using the
following in a VB6mod.

Attribute VB_Name = "modKiosk_Volume"
'Enter each Declare statement as one, single line:
Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal wDeviceID As
Integer, ByVal dwVolume As Long) As Integer
Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal wDeviceID As
Integer, dwVolume As Long) As Integer

'Const SND_ASYNC = &H1
'Const SND_NODEFAULT = &H2
Public Type ulLong
   hiword As Integer
   loword As Integer
End Type

Public Type uvLong
   n As Long
End Type
'As an alternative, you can declare the waveOutSetVolume function by passing
the dwVolume parameter
'as two separate integers, one for the left-channel setting and one for the
right-channel setting.
'Pass the high-order word first and then the low-order word.

'wDeviceID This parameter identifies the waveform-output device. If
' you were to play one wave file, you would set this
' parameter to 0. If you were to play multiple wave files, you
' would set this parameter to 1 for the second, 2 for the third,
' and so on.

'dwVolume For the waveOutSetVloume function, this parameter specifies
' the new volume setting. For the waveOutGetVolume
' function, it specifies a far pointer to a location that will be
' filled with the current volume setting.

' The low-order word contains the left-channel volume setting,
' and the high-order word contains the right-channel volume
' setting.

' A value of &HFFFF represents full volume, and a value of
' &H0000 represents no volume.

' If a device does not support both left and right volume
' control, the low-order word of dwVolume specifies the volume
' level, and the high-order word is ignored.

' Return Value

'?? returns zero if the function is successful. Otherwise, it returns an
error number. Possible return values are:

'MMSYSERR_INVALIHANDLE = 5 Specific device handle is invalid
'MMSYSERR_NOTSUPPORTED = 8 Function isn't supported
'MMSYSERR_NODRIVER = 6 The driver was not installed
'NOTE: Not all devices support volume changes or volume control on both the
left and right channels. Most devices do not support the full 16 bits of
volume-level control and will not use the high-order bits.

You should investigate this and winmm.dll in general....

be aware that since vb types are now different, integers in vb6 are now
shorts in .net and longs are now integers, etc. you will need to change the
declarations etc.

There should maybe be a mute function.

The VB6 class that went with it is
======================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1 'True
  Persistable = 0 'NotPersistable
  DataBindingBehavior = 0 'vbNone
  DataSourceBehavior = 0 'vbNone
  MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsVolumeControl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Const def_VOLUME_CHANGE_FACTOR = &HFFF&

Private CurrentVolLeft As Long
Private CurrentVolRight As Long
Private sldVolume As Long
Private Volume_Change_Factor As Long

Private ulvol As ulLong
Private uvvol As uvLong

Public Property Get CurrentVolume() As Long
   CurrentVolume = sldVolume
End Property
Public Property Let CurrentVolume(Volume As Long)
   If Volume > 65535 Then
      sldVolume = 65535
   ElseIf Volume < 0 Then
      sldVolume = 0
   Else
      sldVolume = Volume
   End If
   SetVolume
End Property

Public Property Let VolumeChangeFactor(Factor As Long)
Attribute VolumeChangeFactor.VB_Description = "Sets/Gets the incremental
value by which the volume is increased/decreased. Valid values are from 0
to 65535. Right and left channnels are set simultaneously."
   If Factor > &HFFFF& Then
      Volume_Change_Factor = &HFFFF&
   ElseIf Factor < 0 Then
      Volume_Change_Factor = 0
   Else
      Volume_Change_Factor = Factor
   End If
End Property

Public Property Get VolumeChangeFactor() As Long
   VolumeChangeFactor = Volume_Change_Factor
End Property

Public Sub IncreaseVolume()
Attribute IncreaseVolume.VB_Description = "Increases the volume level, if
possible, by the VolumeChangeFactor"
   Dim x As Integer

   ' Prevent the channel setting from exceeding the maximum limit:
   If (sldVolume + Volume_Change_Factor) > &HFFFF& Then
      sldVolume = &HFFFF&
   Else
      sldVolume = sldVolume + Volume_Change_Factor
   End If
   SetVolume
End Sub

Public Sub DecreaseVolume()
Attribute DecreaseVolume.VB_Description = "Decreases the volume level, if
possible, by the VolumeChangeFactor"
   Dim x As Integer
   sldVolume = sldVolume - Volume_Change_Factor

   ' Prevent the channel setting from exceeding the maximum limit:
   If sldVolume < &H0& Then sldVolume = &H0&

   SetVolume
End Sub

Private Sub SetVolume()
   Dim x As Integer
  'set volume
   ulvol.hiword = (sldVolume And &H7FFF&) - (sldVolume And &H8000&)
   ulvol.loword = (sldVolume And &H7FFF&) - (sldVolume And &H8000&)
   LSet uvvol = ulvol
   x = waveOutSetVolume(0, uvvol.n)
End Sub

Private Sub Class_Initialize()
   Dim x As Integer
   Dim BothVolumes As Long
 ' Note that the waveid is 0 indicating the first wave output device.
 ' If you were to play multiple wavefiles on multiple wave output devices
 ' you would use 1 for the second wave output device, 2 for the third and
 ' so on.
 ' This code will retrieve the current volume setting
   x = waveOutGetVolume(0, BothVolumes)

   ' This code isolates the low-order word.
   ' Note that the value &HFFFF& is a Long Integer, which is the same
   ' as 0000FFFF, but because Visual Basic would automatically
   ' truncate this to FFFF, you must force the logical operation to use
   ' a four-byte Long Integer (0000FFFF) rather than a two-byte Integer
   ' (FFFF). This is accomplished by using the type casting
   ' character (&).

   sldVolume = BothVolumes And &HFFFF&
   Volume_Change_Factor = def_VOLUME_CHANGE_FACTOR
End Sub

======================

Hope this helps give you an idea of some posibilities. I am unaware of
another way.

Shane

"Bob Day" <BobDay@TouchTalk.net> wrote in message
news:%23RYDwux7DHA.1428@TK2MSFTNGP12.phx.gbl...
> Using VS 2003, VB. Net, MSDE...
>
> Usining task sheduler, I wish to mute the volume in the .bat file that
task
> scheduler runs (windows XP Pro). I don't see anyway to do this via a .bat
> line command (if there is, please let me know).
>
> So the next option would be to write a small .net program that would do it
> and run that via task scheduler. How would you mute the volume in code in
> the vb.net program? I'm not quire sure where to get started on this.
>
> Thanks!
>
> Bob Day
>
>



Relevant Pages

  • Re: DC another Problem
    ... > Private PointsDraw As ClassPoints ... > Private Sub Command1_Click ... > Dim p As Classpoint ... > Public Property Let X ...
    (microsoft.public.vb.winapi.graphics)
  • Re: DC another Problem
    ... >>Private PointsDraw As ClassPoints ... >>End Sub ... >>Dim p As Classpoint ... >>Public Property Let X ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Get return from form in ActiveX dll
    ... Sub Test() ... Private Sub MB_evtButton(strCaption As String) ... Public Property Set ExcelApp ...
    (microsoft.public.vb.general.discussion)
  • Re: set fontsize with variable
    ... Public Function MsgBoxDLL(Optional strPrompt As String, ... Private m_Prompt As String ... Public Property Let Prompt ... Private Sub cmdButton1_Click ...
    (microsoft.public.vb.general.discussion)
  • Re: Getting Windows Display Name
    ... Private Type WKSTA_USER_INFO_1 ... usri3_script_path As Long 'Pointer to a Unicode string specifying the path for the user's logon script file. ... Dim bufptr As Long ... Public Property Get PasswordAgeAs Long ...
    (microsoft.public.access.modulesdaovba)