C# 控制系统音量,静音 (加减按钮形式)

王朝学院·作者佚名  2009-11-04
窄屏简体版  字體: |||超大  

view plaincopy to clipboardprint?

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace VolumnSet

{

public partial class Form1 : Form

{

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]

static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);

const uint WM_APPCOMMAND = 0x319;

const uint APPCOMMAND_VOLUME_UP = 0x0a;

const uint APPCOMMAND_VOLUME_DOWN = 0x09;

const uint APPCOMMAND_VOLUME_MUTE = 0x08;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

//加音量

SendMessage(this

.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);

}

private void button2_Click(object sender, EventArgs e)

{

//减音量

SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

//静音

SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航