473,288 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Mute volume in vb.net program

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
Nov 20 '05 #1
2 14367
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" <Bo****@TouchTalk.net> wrote in message
news:%2****************@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

Nov 20 '05 #2
Thanks!
Bob Day

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rafa | last post by:
Hi I'm just learning C and I was trying to do an exercise in a book which asks me to write a program to calculate the volume of a sphere. I know the formula is Volume = (4/3)*(Pi)*(Radius)^3 and...
1
by: Ken Lemieux | last post by:
It's my understanding in order to mute the pc microphone from c# requires DirectX 9. Could anyone confirm this for me, and provide examples or technicle refrences where it may be discussed? ...
0
by: Steve | last post by:
If I mute the master volume control, is there anyway my AP can detect dynamically?
0
by: steve | last post by:
I am writing a AP, can anyone help me how can my AP detect user mute/unmute or volume up/down from windows volume control?
16
by: Basil Fawlty | last post by:
Hi everyone, I have an assignment, to create a simple VB program that computes the volume of a cylinder. The Form is pretty simple, it has a label and text box for base radius, another for height...
2
by: vinnycoyne | last post by:
Hi there, I am implementing a mute button on my application which successfully changes the mute status of the mixer in windows. I would like to know if there is a way to detect the mixer being...
1
by: Dennis Heavey | last post by:
Windows xp WMP11. How do I mute or set the volume on windows media player with VB6???
0
by: streammalvern | last post by:
I created a video using a pre-made fla skin that I edited so that it only shows the play/pause, stop, seek, mute, and volume features. It all works fine, however I was asked to have it set that the...
1
by: Kartoffelen | last post by:
Hi! I got this game I'm playing, and it contains this really annoying music, and I like to listen to real music while playing games. Of some reason, theres no mute button I can use to turn of this...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.