Solved

Muting and UnMuting the Windows Volume using Visual Basic 6

Posted on 2004-04-14
4
1,836 Views
Last Modified: 2013-11-25
Is there an API or simple set of commands I can use to Mute all of the audio output from a MS Windows PC system, and then easily UnMute?

I would like a command set or API which has the same effect as clicking the "Mute" Checkbox within the windows volume control displayed in the taskbar.

I have tried the "auxSetVolume" function from the winmm.dll file, to set the volume to zero, however it does not appear to work. I may however have been using incorrect syntax.

Ideally it would be nice if there was a simple API or command such as "auxMuteVolume" and "auxUnMuteVolume", but alas things rarely work out that easily.

Example code for Visual Basic 6 would be useful...

Thankyou.
0
Comment
Question by:Loquerion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10825364
Take a look at the Accepted Answer I posted here: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20923876.html

Regards,

Idle_Mind
0
 

Author Comment

by:Loquerion
ID: 10826532
I have had a look at those links, and the ones that link from there... although I feel I am now closer to the answer, it still eludes me:

Am I right in thinking that I should be declaring two DLL proceedures from "winmm.dll" in a module something like:

----------
Public Declare Function OpenMixer Lib "winmm.dll" (ByVal MixerNumber As Long) As Long

Public Declare Function SetMute Lib "winmm.dll" (Control As MUTE_CONTROL, ByVal MuteState As Boolean) As Boolean
----------

then just calling them where I need them as:

----------
Public Sub MuteVolume()

     OpenMixer(0)
     SetMute(SPEAKER_MUTE, True)

End Sub
----------

because that doesnt work... I get an error "Cannot find DLL entry point OpenMixer in winmm.dll" on calling the open mixer, and I then get an error of "User-defined type not defined" on trying to compile from the SetMute...

...

I believe the code that you pointed to:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20923876.html

...has the ability to do what I need, but I may be Hamming up the module declarations as they are not actually set out word for word in code.


** I do not understand what the "Control As MUTE_CONTROL" actually does... i think that my problem my lie there...
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 10826592
The API's make use of custom type structures.  Your best off just copying and pasting everything below the

' ----------------------------------------------------------------------
' Module Code
' ----------------------------------------------------------------------

mark into a module even if you are not going to use all of it.  Try creating the project as I described it to see how it works and then try paring it down to the bare minimum after that.

Idle_Mind
0
 

Author Comment

by:Loquerion
ID: 10826969
right... i will try that, but is it not possible to just reference that API, including its custom structures straight from the DLL? It just seems, (and maybe this is just how it is), a little silly to have to include a large WHACK of a DLL file in your project instead of referencing it...

lol... i think i know what you mean though... and i recall that there were some errors in VB when it comes to parsing DLL files... i will give it a go and get back to you.

**

ok, i lied... i tried it there now, and it works... so worst case scenario i will have a slightly larger source code printout than i would have liked, but it does work... i would however like to try and get it working with just a few DLL referencesinstead of a cut/paste job of the whole of "winmm.dll"...

Thanks again, will be in touch...
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question