• 0

[C#] Adjusting system sound volume


Question

Hi,

I was wondering if somebody knows how I can adjust the system sound volume using C#.NET ? I want my application to increase or decrease the system's sound volume. I want to develop an application that functions similar to how Windows volume control functions:

post-62656-1104152753_thumb.jpg

Can somebody please tell me how to do it? Or at least, tell me how to adjust the system's volume control?

Thanks in advance - any help will be appreciated :)

P.S. - I will also be happy to accept a VB.NET code - I can try to convert it to C#.

Link to comment
https://www.neowin.net/forum/topic/262787-c-adjusting-system-sound-volume/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Wow, that's a lot of code for just increasing volume.

 

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Test
{
public partial class Form1 : Form
{
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;

[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg,
IntPtr wParam, IntPtr lParam);

public Form1()
{
InitializeComponent();
}

private void btnMute_Click(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
}

private void btnDecVol_Click(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_DOWN);
}

private void btnIncVol_Click(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_UP);
}
}
}
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.