تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
للتحكم في درجه الصوت الويندوز sound volume
#1
كاتب الموضوع : AhmedEssawy

المتغير trackWave.Value
هو الذي يحكم قيمه الصوت الحاليه ...

المتغير
NewVolumeAllChannels
هو الذي يتم من خلاله تغير مستوي الصوت ...


كود :
[FONT=Courier New, Courier, monospace][SIZE=2][color=#0000ff]using[/color][/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2] System;
[color=#0000ff]using[/color] System.Collections.Generic;
[color=#0000ff]using[/color] System.ComponentModel;
[color=#0000ff]using[/color] System.Data;
[color=#0000ff]using[/color] System.Drawing;
[color=#0000ff]using[/color] System.Text;
[color=#0000ff]using[/color] System.Windows.Forms;
[color=#0000ff]using[/color] System.Runtime.InteropServices;[/SIZE][/FONT]
[FONT=Courier New, Courier, monospace][SIZE=2][color=#0000ff]namespace[/color][/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2] VolumeControl
{
[color=#0000ff]public partial class[/color] [color=#0099cc]Form1[/color] : [color=#0099cc]Form[/color]
{[/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2]
[[color=#0099cc]DllImport[/color]([color=#990000]"winmm.dll"[/color])]
[color=#0000ff]public static extern int[/color] waveOutGetVolume([color=#0099cc]IntPtr[/color] hwo, [color=#0000ff]out uint[/color] dwVolume);[/SIZE][/FONT]
[FONT=Courier New, Courier, monospace][SIZE=2][[color=#0099cc]DllImport[/color]([color=#990000]"winmm.dll"[/color])]
[color=#0000ff]public static extern int[/color] waveOutSetVolume([color=#0099cc]IntPtr[/color] hwo, [color=#0000ff]uint[/color] dwVolume);[/SIZE][/FONT]

[FONT=Courier New, Courier, monospace][SIZE=2][color=#0000ff]public[/color][/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2] Form1()
{
InitializeComponent();
[/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#009900]// By the default set the volume to 0[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#0000ff]uint[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][COLOR=#000000] CurrVol = 0;
[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#009900]// At this point, CurrVol gets assigned the volume[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#000000]waveOutGetVolume([COLOR=#0099cc]IntPtr[/color].Zero, [color=#0000ff]out[/color] CurrVol);
[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#009900]// Calculate the volume[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][COLOR=#000000]
[color=#0000ff]ushort[/color] CalcVol = ([color=#0000ff]ushort[/color])(CurrVol & 0x0000ffff);
[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#009900]// Get the volume on a scale of 1 to 10 (to fit the trackbar)[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#000000]trackWave.Value = CalcVol / ([COLOR=#0000ff]ushort[/color].MaxValue / 10);[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2]
}

[color=#0000ff]private void[/color] trackWave_Scroll([color=#0000ff]object[/color] sender, [color=#0099cc]EventArgs[/color] e)
{
[/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#009900]// Calculate the volume that's being set[/color][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][COLOR=#000000]
[color=#0000ff]int[/color] NewVolume = (([color=#0000ff]ushort[/color].MaxValue / 10) * trackWave.Value);
[color=#009900]// Set the same volume for both the left and the right channels[/color]
[color=#0000ff]uint[/color] NewVolumeAllChannels = ((([color=#0000ff]uint[/color])NewVolume & 0x0000ffff) | (([color=#0000ff]uint[/color])NewVolume << 16));
[color=#009900]// Set the volume[/color]
[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, mono][SIZE=2][color=#000000]waveOutSetVolume([COLOR=#0099cc]IntPtr[/color].Zero, NewVolumeAllChannels);[/COLOR][/SIZE][/FONT][FONT=Courier New, Courier, monospace][SIZE=2]
}[/SIZE][/FONT]
[FONT=Courier New, Courier, monospace][SIZE=2]}[/SIZE][/FONT]
[FONT=Courier New, Courier, monospace][SIZE=2]}[/SIZE][/FONT]
}}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم