使用しているコードが次の場合、コンピューターのマスター ボリューム コントロールに触れずに、アプリケーションでサウンドをミュート/ミュート解除するにはどうすればよいですか。
My.Computer.Audio.Play(My.Resources.audio_here, AudioPlayMode.Background)
使用しているコードが次の場合、コンピューターのマスター ボリューム コントロールに触れずに、アプリケーションでサウンドをミュート/ミュート解除するにはどうすればよいですか。
My.Computer.Audio.Play(My.Resources.audio_here, AudioPlayMode.Background)
winmm.dllのwaveOutSetVolume
および関数を見てください。waveOutGetVolume
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByVal dwVolume As Integer) As Integer
Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Integer, ByRef lpdwVolume As Integer) As Integer
ターゲット マシンの OS バージョンによっては、新しいAPIの使用を検討する必要がある場合がMMDevice
あります。EndpointVolume
[DllImport("winmm.dll")]
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
//mute application
private void mute(){
{
int NewVolume = 0; //set 0 to unmute
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}
//unmute application
private void unmute(){
{
int NewVolume = 65535; //set 65535 to unmute
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}