Vb判断系统声音强弱的源码的简单介绍
VB获取系统中声音大小,求完整代码
API
Public Declare Function waveOutGetVolume Lib "winmm.dll" Alias "waveOutGetVolume" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Public Declare Function waveOutSetVolume Lib "winmm.dll" Alias "waveOutSetVolume" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
以下是MSDN上的
waveOutGetVolume 取得系统声音
The waveOutGetVolume function retrieves the current volume level of the specified waveform-audio output device.
MMRESULT waveOutGetVolume(
HWAVEOUT hwo,
LPDWORD pdwVolume
);
waveOutSetVolume 设置系统声音
The waveOutSetVolume function sets the volume level of the specified waveform-audio output device.
MMRESULT waveOutSetVolume(
HWAVEOUT hwo,
DWORD dwVolume
);
Parameters
hwo
Handle of an open waveform-audio output device. This parameter can also be a device identifier.
dwVolume
New volume setting. The low-order word contains the left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
If a device does not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and the high-order word is ignored.
Return Values
Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following:
Value Description
MMSYSERR_INVALHANDLE Specified device handle is invalid.
MMSYSERR_NODRIVER No device driver is present.
MMSYSERR_NOMEM Unable to allocate or lock memory.
MMSYSERR_NOTSUPPORTED Function is not supported.
vb检测系统声音
定义调用声音文件函数时用到了Windows播放声音的API函数。现先将此API函数作简单介绍: sndPlaySound(参数1,参数2)其中:参数1描述要播放的声音文件的位置和文件名;参数2的取值能决定播放声音的模式。参数2的主要取值介绍如下: 取&H0时:为同步播放模式; 取&H1时:为异步播放模式; 取&H2时:当声音文件未找到就停止播音返回; 取&H8时:为循环播放模式。 当调用函数成功,就播放有关声音文件,并且函数的返回值为非0;函数调用失败,函数的返回值为0。 定义调用声音文件函数的具体步骤如下: ①在C盘根目录上建立一个名为Sound的文件夹,在此文件夹中放入5个你所需要的声音文件; ②在VB5.0状态进入“工程”菜单中的“添加模块”再选用“新建”中的“模块”; ③在模块的“通用”中输入下面代码,进行调用API函数的声明; Declare Function sndPlaySound Lib "winmm.dll" Alias “sndPlaySoundA" (ByV al lpszSoundName As String, ByVal uFlags As Long) As Long Dim fil As String ④在模块中输入以下代码,定义调用声音文件函数。 Public Function sound(n As Integer) As Integer Dim x As Integer Select Case n Case 1 fil = "c:\sound\beep3.wav" x = sndPlaySound(0, 0) x = sndPlaySound(fil, &H1 Or &H2) sound = x Case 2 fil = "c:\sound\hit8.wav" x = sndPlaySound(0, 0) x = sndPlaySound(fil, &H1 Or &H2) sound = x Case 3 fil = "c:\sound\net7.wav" x = sndPlaySound(0, 0) x = sndPlaySound(fil, &H1 Or &H2) sound = x Case 4 fil = "c:\sound\out12.wav" x = sndPlaySound(0, 0) x = sndPlaySound(fil, &H1 Or &H2) sound = x Case 5 fil = "c:\sound\spin5.wav" x = sndPlaySound(0, 0) x = sndPlaySound(fil, &H1 Or &H2) sound = x Case Else sound = 0 End Select End Function 新定义的调用声音函数格式为:sound(n),其中n的取值为1至5的正整数。利用此函数可调用5个不同的声音文件。下面是使用sound函数的演示程序: ①如图在form窗口设置6个命令控件; ②在这些命令控件的Click事件中入分别输入以下代码。 Private Sub Command1_Click() l = sound(1) End Sub Private Sub Command2_Click() l = sound(2) End Sub Private Sub Command3_Click() l = sound(3) End Sub Private Sub Command4_Click() l = sound(4) End Sub Private Sub Command5_Click() l = sound(5) End Sub Private Sub Command6_Click() End End Sub 运行程序后,单击有关按钮就能调用所指定的声音文件,发出各种声音。
如何使用VB判断有麦克风输入声音音量的大小?
代码写出来有些烦锁,请你借助 Baidu、Google 查找:“mciSendString”、“mciSendCommand”、“winmm.dll” 相关文章,你一定会得到收获。
VB声音源代码
要是你不嫌弃我这个声音太简朴的话就用吧。播一个音阶。建一个Command1,单击按钮即可。
代码如下。
===============
Const Do0 = 264
Const Re = 297
Const Mi = 330
Const Fa = 352
Const Sol = 396
Const La = 440
Const Ti = 495
Const Do1 = 528
Const T4 = 1000
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Sub Command1_Click()
Beep Do0, T4
Beep Re, T4
Beep Mi, T4
Beep Fa, T4
Beep Sol, T4
Beep La, T4
Beep Ti, T4
Beep Do1, T4
End Sub
VB,实现系统主音量调节,音量控制
系统自带的主音量调节的窗口
实际上是一个单独的exe文件 Sndvol32.exe
位于windows文件夹中
只要调用这个程序就可以了
Private Sub Command1_Click()
Shell "Sndvol32.exe", 1
End Sub
调出 声音和音频设备 属性 最简单的
Private Sub Command1_Click()
Shell "rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0", 1
End Sub