在 Windows 7 中获取当前系统音量 [英] Get the current system volume in Windows 7
问题描述
如何在 Windows 7 中获取系统当前的主音量?
How can I get the current master volume of the system in Windows 7?
我在 Google 上查了一下,但每个解决方案都返回了类似 -1
或 4686346
的值,但没有明确解释它们的含义.
I looked up in Google, but every solution returned values like -1
or 4686346
without a clear explanation of what they mean.
推荐答案
您正在寻找 EndpointVolume
API. 这是 Windows Vista 中发布的新音频 API 的一部分,可用于获取或设置主音量.
You're looking for the EndpointVolume
API. This is part of the new audio APIs that were released in Windows Vista, and it can be used to get or set the master volume.
由于您不需要支持 Vista 之前的 Windows 版本(即 Windows XP),因此这项工作变得相当容易,因为在这些操作系统版本之间对相关基础结构进行了重大更改.这可能是您尝试过的现有示例无法正常工作的原因.
This undertaking is made considerably easier by the fact that you do not need to support versions of Windows prior to Vista (namely Windows XP), because there were substantial changes made to the relevant infrastructure between those OS releases. This is likely the reason why the existing samples you've tried didn't work properly.
CodeProject 上有一个完整的托管包装库:Vista Core Audio API Master Volume Control.它可能实现了比您需要的更多的功能,但您可以了解需要做什么才能从您的 C# 应用程序中确定主系统卷.
There's a complete managed wrapper library available on CodeProject: Vista Core Audio API Master Volume Control. It probably implements more functionality than you need, but you can get an idea of what you need to do to determine the master system volume from your C# application.
这篇关于在 Windows 7 中获取当前系统音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!