I have a console program, which needs a way to mute the sound on my computer.
Here's the code that does this, but it was written for the WF. There is an easier-analogue for the console program?
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace VolumeOff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern uint waveOutGetVolume(uint hwo, ref uint dwVolume);
[DllImport("winmm.dll", SetLastError = true, CallingConvention =
CallingConvention.Winapi)]
public static extern int waveOutSetVolume(uint uDeviceID, uint dwVolume);
private void button1_Click(object sender, EventArgs e)
{
uint volume = 0;
uint hWO = 0;
waveOutGetVolume(hWO, ref volume);
textBox1.Text = volume.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
uint hWO = 0;
waveOutSetVolume(hWO, Convert.ToUInt32(textBox1.Text.ToString()));
}
}
}
Edit 1: By the way, this code works a bit wrong. With this slider to adjust the volume in the system tray (which adjusts the volume in Windows) does not move. The impression is that my application does not regulate the volume of the system, but something else.