[DllImport("winmm.dll")]
private static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); [DllImport("winmm.dll")]
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume); /// <summary>
/// Returns volume from 0 to 10
/// </summary>
/// <returns>Volume from 0 to 10</returns>
public static int GetVolume()
{
uint CurrVol = 0;
waveOutGetVolume(IntPtr.Zero, out CurrVol);
ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
int volume = CalcVol / (ushort.MaxValue / 10);
return volume;
} /// <summary>
/// Sets volume from 0 to 10
/// </summary>
/// <param name="volume">Volume from 0 to 10</param>
public static void SetVolume(int volume)
{
int NewVolume = ((ushort.MaxValue / 10) * volume);
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}

  

winmm.dll获取和设置声音的更多相关文章

  1. 使用winmm.dll 获取麦克风声音数据

    //录音 /// <summary> /// 初始化录音环境 /// </summary> /// <returns></returns> public ...

  2. 通过winmm.dll控制声音播放

    介绍如何通过winmm.dll播放声音 首先导入两个函数 /// <summary> /// 向媒体控制接口发送控制命令 /// </summary> /// <para ...

  3. winmm.dll包含函数

    DLL 文件: winmm 或者 winmm.dll DLL 名称: Windows Multimedia API 描述: winmm.dll是Windows多媒体相关应用程序接口,用于低档的音频和游 ...

  4. Windows高速定时器,多媒体定时器winmm.dll库的使用

    项目里面用到的这些看起来名字高大上的定时器测试下来也是非常不准.看了源码发现也是用System.Timers.Timer或者用的是Thread休眠的方式来实现的.100毫秒就不准了.直到一番搜索,发现 ...

  5. [WinAPI] API 12 [获取程序所在的目录、程序模块路径,获取和设置当前目录]

    Windows系统提供一组API实现对程序运行时相关目录的获取和设置.用户可以使用GetCurrentDirectory和SetCurrentDirectory获取程序的当前目录,获取模块的路径使用G ...

  6. windows 自带winmm.dll播放音频问题

    同事用的一个录音小程序在他机器上可以用,换了两个电脑不能用,获取音频长度时总是0,检查代码也没有发现具体问题.最后发现是电脑声卡驱动的问题.更新声卡驱动好了. 附上播放音频的代码: 首先,导入dll文 ...

  7. WPF备忘录(2)WPF获取和设置鼠标位置与progressbar的使用方法

    一.WPF 中获取和设置鼠标位置 方法一:WPF方法 Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.S ...

  8. WPF 窗口句柄获取和设置

    原文:WPF 窗口句柄获取和设置 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83347163 ...

  9. WPF获取和设置鼠标位置与progressbar的使用方法

    一.WPF 中获取和设置鼠标位置 方法一:WPF方法 Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.S ...

随机推荐

  1. request.getInputStream() 流只能读取一次问题

    问题: 一次开发过程中同事在 sptring interceptor 中获取 request body 中值,以对数据的校验和预处理等操作 .导致之后spring 在读取request body 值做 ...

  2. PAT 1121 Damn Single[简单]

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  3. Bar Mitzvah Attack分析

    结合RC4算法实现,简单分析一下Bar Mitzvah Attack攻击的原理,并以WEP破解过程来举例说明通用的破解方式.(个人觉得RC4早已经过时,要想避免该攻击,应该采用更好的加密算法,如:cc ...

  4. ios 常见问题解决 以及小技巧

    1.使用cocoaPods引用第三方类库,报错:file not found   . 解决方案:设置 Project->Info->Configurations之后  clear ,然后再 ...

  5. [caffe]caffe资料收集

    1.caffe主页,有各种tutorial. 2.Evan Shelhamer的tutorial,包括视频.

  6. 20145324 《Java程序设计》第4周学习总结

    20145324 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 1.继承是为避免多个类间重复定义共同行为 A extends B A继承B的行为 2.一个子类只能继承一个父 ...

  7. Eye Protection FAQ

    Q: Why does smart protection not work? A: Please make sure the checkbox "Eye Protection" i ...

  8. 读取Jar中的json文件

    现在操作json的jar 都是用的fastjson, 如果需要读取的json文件不在jar包里面,则可以这样获取到: String path = this.getClass().getClassLoa ...

  9. 爬虫框架Scrapy之案例二

    新浪网分类资讯爬虫 爬取新浪网导航页所有下所有大类.小类.小类里的子链接,以及子链接页面的新闻内容. 效果演示图: items.py import scrapy import sys reload(s ...

  10. C#设计模式之控制反转即依赖注入-微软提供的Unity

    使用VS2015的Nuget管理器下载Unity. 程序员接口类: 1 namespace UnityDemo 2 { 3 public interface IProgrammer 4 { 5 voi ...