How do I know if the main loud sound is muted?

I use the following to mute / unmute the wizard sound on my computer. Now I am looking for a way to determine the state without sound. Is there an equally easy way to do this in C #?

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
+3
source share
3 answers

Credit RRUZ in the comments above. See Stackoverflow.com/questions/294292. The only problem is that you need a compatibility mode.

0
source

Hi, I just stumbled upon this old topic, but while shaving on the same issue.

I decided to use the following:

using System.Runtime.InteropServices;

...

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);


private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int APPCOMMAND_VOLUME_UP = 0xA0000;
private const int APPCOMMAND_VOLUME_DOWN = 0x90000;               
private const int WM_APPCOMMAND = 0x319;        

...

// mute (toggle)
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);


// unmute
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_DOWN);

Turning off the sound does not always turn off the sound, it switches, but if you first call "unmute", you must be golden.

Regards Kurt

+8
source

Check out the following tutorial . I have never played with Mixer in C # (or any other language), so I assume that they are true in P / Invoking for the Win32 API and that they do not reinvent the wheel. You can download this example, and I think the GetMixer () method will do what you want.

0
source

Source: https://habr.com/ru/post/1782710/


All Articles