Solved

Muting and UnMuting the Windows Volume using Visual Basic 6

Posted on 2004-04-14
4
1,809 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
  • 2
  • 2
4 Comments
 
LVL 85

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 85

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent user closing word document opened with VB6 6 84
Help me. 3 69
MS Access 03, TransferText, decimal places 8 85
checkbox to hide entire section 10 62
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 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