I would like to write an app that mutes/unmutes the speaker with a single click.
(My external ones and internal as well.)
I think a conversion of this may work.
Am I going in the right direction?
Or maybe use devcon to turn off the device?
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
//If the reason for the session switch is lock or unlock
//send the message to mute or unmute the system volume
if (e.Reason == SessionSwitchReason.SessionLock)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
}
else if (e.Reason == SessionSwitchReason.SessionUnlock)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
}
}
er you'll have to decipher :lol....
oexSetVolume PROC USES esi edi oexVolume:DWORD
; Left 0000 - FFFF and Right 0000 - FFFF
LOCAL oexOldVolume:DWORD
; if (waveOutGetVolume(NULL, &dwVolume) == MMSYSERR_NOERROR)
; waveOutSetVolume(NULL, 0); // mute volume
; // later point in code, to unmute volume...
; waveOutSetVolume(NULL, dwVolume);
.if xR(waveOutGetVolume, 0, ADDR oexOldVolume) == MMSYSERR_NOERROR
invoke waveOutSetVolume, 0, oexVolume
.endif
ret
oexSetVolume ENDP
I did not have much luck.
But I also have a sinus infection.
I modified it to fix a bug a few minutes after initial post.... I tested it just now and it worked ok for me on Windows XP with a wav file....
It doesnt mute the main volume however
Bill Craven gives an example in masm32\examples\bcraven\mvolume
his example actually provides a slide to control the volume, which is more than you want
from looking at his code, i think you want to start out with
INCLUDE \masm32\include\winmm.inc
INCLUDELIB \masm32\lib\winmm.lib
then use mixerOpen, mixerSetControlDetails, and mixerClose with the appropriate structures
oh....
and mixerGetControlDetails to save the initial value for unmute
I wrote some similar programs that use winmm.dll and guess what? The winmm.dll functions do not work in Windows Vista and Seven. It's an entirely new sound system and it breaks the old programs. I was a little upset to say the least. I still haven't rewritten them as they were just a convenience for me. The new Core Audio API is COM based.
[Edit] I just tried Bill Craven's example on this Vista laptop and it's working. Maybe they fixed the shims for the old functions in a Service Pack. When Vista first came out they did not work and a lot of people were upset about it. I'll have to take another look at my programs now.
[Edit] OK, after taking a closer look, I see that Bill's program is not controlling the main volume as was intended, just the volume for the individual program. So, it does not work correctly on Windows Vista and Seven.